建立四模块 CMake 骨架与 line1 样例。

- compiler / vm 空静态库,host 可执行打印版本
- 顶层解开 add_subdirectory,tests 接入 CTest(host_version 通过)
- examples/line1 落地 project.toml 与三个 .st
- Types.h 注释补饱和规则,与 Doc/isa 一致
- .gitignore 忽略 Doc/会话记录.md
This commit is contained in:
2026-08-19 10:09:27 +08:00
parent ff244888c3
commit 9a35a881d1
14 changed files with 135 additions and 4 deletions
+1
View File
@@ -1,2 +1,3 @@
build/** build/**
.vscode/** .vscode/**
Doc/会话记录.md
+7 -3
View File
@@ -10,6 +10,10 @@ project(Stator
include("${CMAKE_SOURCE_DIR}/cmake/Standards.cmake") include("${CMAKE_SOURCE_DIR}/cmake/Standards.cmake")
add_subdirectory(isa) add_subdirectory(isa)
# add_subdirectory(compiler) add_subdirectory(compiler)
# add_subdirectory(vm) add_subdirectory(vm)
# add_subdirectory(host) add_subdirectory(host)
# 自动化用例
enable_testing()
add_subdirectory(tests)
+13
View File
@@ -0,0 +1,13 @@
# CMake最低版本
cmake_minimum_required(VERSION 3.21)
# 工程名、版本号、工程描述
project(Compiler
VERSION 0.1
DESCRIPTION "ST / toml 编译器")
include_directories(./include)
# 词法、语法、符号表、类型检查、codegen、链接都留在 compiler 一个库里
add_library(compiler STATIC
./src/Lexer.cpp)
+8
View File
@@ -0,0 +1,8 @@
/**
* @file Lexer.cpp
* @brief 词法分析(12.4 实现)
* @date 2026-08-19
*/
namespace compiler {
}
+7
View File
@@ -0,0 +1,7 @@
(* globals.st *)
VAR_GLOBAL
EmergencyStop : BOOL := FALSE;
I0_0 : BOOL;
I0_1 : BOOL;
Q0_0 : BOOL;
END_VAR
+8
View File
@@ -0,0 +1,8 @@
(* main.st *)
PROGRAM MAIN
VAR
starter : MotorStarter;
END_VAR
starter(start := I0_0, stop := I0_1);
Q0_0 := starter.Q;
END_PROGRAM
+13
View File
@@ -0,0 +1,13 @@
(* motor.st *)
FUNCTION_BLOCK MotorStarter
VAR_EXTERNAL
EmergencyStop : BOOL;
END_VAR
VAR_INPUT
start, stop : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
Q := start AND NOT stop AND NOT EmergencyStop;
END_FUNCTION_BLOCK
+28
View File
@@ -0,0 +1,28 @@
[project]
name = "line1"
entry = "program MAIN"
cycle_limit = 100000
dt_ms = 10
[files]
st = ["globals.st", "motor.st", "main.st"]
# 全工程只允许这一处出现 VAR_GLOBAL(第一版:单个文件)
[gvl]
file = "globals.st"
# 可选:I/O 绑定。不创造变量,var 必须已在 GVL 里声明
[[io.input]]
var = "EmergencyStop"
channel = 0
bit = 2
[[io.input]]
var = "I0_0"
channel = 0
bit = 0
[[io.output]]
var = "Q0_0"
channel = 0
bit = 0
+10
View File
@@ -0,0 +1,10 @@
# CMake最低版本
cmake_minimum_required(VERSION 3.21)
# 工程名、版本号、工程描述
project(Host
VERSION 0.1
DESCRIPTION "可执行入口:编译并跑扫描周期")
add_executable(host
./src/main.cpp)
+14
View File
@@ -0,0 +1,14 @@
/**
* @file main.cpp
* @brief host 可执行入口
* @date 2026-08-19
*/
#include <cstdio>
int main(int argc, char** argv) {
(void)argc;
(void)argv;
std::printf("Stator host 0.1\n");
return 0;
}
+2
View File
@@ -11,6 +11,8 @@
namespace isa { namespace isa {
namespace types { namespace types {
// 定宽类型。整数溢出规则:饱和(夹到 INT 最小/最大),
// 由 compiler 与 vm 按同一规则实现,见 Doc/isa/指令与映像.md。
using BOOL = uint8_t; using BOOL = uint8_t;
using INT = int16_t; using INT = int16_t;
using TIME = uint64_t; using TIME = uint64_t;
+3
View File
@@ -0,0 +1,3 @@
# 自动化用例:先放一个必过的空测试,验证 CTest 接线
add_test(NAME host_version
COMMAND host)
+12
View File
@@ -0,0 +1,12 @@
# CMake最低版本
cmake_minimum_required(VERSION 3.21)
# 工程名、版本号、工程描述
project(VM
VERSION 0.1
DESCRIPTION "寄存器虚拟机")
include_directories(./include)
add_library(vm STATIC
./src/Machine.cpp)
+8
View File
@@ -0,0 +1,8 @@
/**
* @file Machine.cpp
* @brief 寄存器虚拟机(12.9 实现)
* @date 2026-08-19
*/
namespace vm {
}