阶段 D 步骤 11:文档同步 + 提交(指令配置全流程收尾)。
- stb文件格式.md:288 字节真实拆解(头 104 含型号标识 STATOR1@0x48、函数表 0x68、 代码 0x80 fn0 RET=0x21、数据段 0xC8 7 槽、SHA-256 尾 0x100);工具验证与执行器关系更新 - STCompiler使用说明.md:--machine 参数(编译/disasm 必填、打印模式不需要)、 .stb 加固说明、288 字节示例、当前状态(可编译+可执行+配置驱动) - 执行器入口.md:读取时型号/SHA 校验拒绝 - ctest 14/14 全绿
This commit is contained in:
@@ -15,45 +15,52 @@ ctest --test-dir build/gcc-debug # 测试(当前 9 个用例)
|
||||
## 用法
|
||||
|
||||
```text
|
||||
STCompiler <project.toml> [-o <name>.stb]
|
||||
STCompiler <name>.stb --disasm
|
||||
STCompiler <project.toml> [-o <name>.stb] --machine <machine.toml>
|
||||
STCompiler <name>.stb --disasm --machine <machine.toml>
|
||||
```
|
||||
|
||||
| 参数 | 作用 |
|
||||
|---|---|
|
||||
| `<project.toml>` | 工程文件(必填) |
|
||||
| `-o <name>.stb` | 编译并写出映像文件;**缺省时只打印文件集合与工程哈希**(12.3 阶段行为) |
|
||||
| `-o <name>.stb` | 编译并写出映像文件(+ sidecar);**缺省时只打印文件集合与工程哈希**(不需 `--machine`) |
|
||||
| `--machine <machine.toml>` | 机器定义(指令 opcode / 类型 / FB 布局,见 `Doc/isa/指令配置.md`);**编译与 `--disasm` 必填**,加载/校验失败报错退出 |
|
||||
| `<name>.stb --disasm` | **反汇编一个已编译的映像**(不重新编译,见下) |
|
||||
| `--help` | 打印帮助 |
|
||||
|
||||
退出码:`0` 成功;`1` 编译失败(错误信息打到 stderr)。
|
||||
退出码:`0` 成功;`1` 失败(错误信息打到 stderr)。
|
||||
|
||||
## 反汇编(--disasm)
|
||||
|
||||
对已编译的 `.stb` 逐段查看:段摘要、函数表逐条指令(文件绝对偏移)、常量表、数据段 hex。
|
||||
对已编译的 `.stb` 逐段查看:段摘要(含型号与 SHA 校验)、函数表逐条指令(文件绝对偏移)、常量表、数据段 hex。
|
||||
|
||||
```bash
|
||||
$ STCompiler line1.stb --disasm
|
||||
image: line1.stb (184 bytes, 2 functions, 4 globals, entry fn 1)
|
||||
dt_ms=10 cycle_limit=100000 hash=0xc3fe4ae74ad45900
|
||||
$ STCompiler line1.stb --disasm --machine machine.toml
|
||||
image: line1.stb (288 bytes, 2 functions, 4 globals, entry fn 1)
|
||||
dt_ms=10 cycle_limit=100000 hash=0xc3fe4ae74ad45900 model=STATOR1 sha=ok
|
||||
functions:
|
||||
fn 0: nregs=8, offset=0, len=1
|
||||
0x0060 RET
|
||||
0x0080 RET
|
||||
fn 1: nregs=13, offset=4, len=17
|
||||
0x0064 LOAD_I r8, 1
|
||||
0x0068 STORE_GLOBAL r8, 8
|
||||
0x006c LOAD_GLOBAL r9, 2
|
||||
0x0084 LOAD_I r8, 1
|
||||
0x0088 STORE_GLOBAL r8, 4
|
||||
...
|
||||
data (16 bytes):
|
||||
0x0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
data (56 bytes):
|
||||
0x0000: ...
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- 指令偏移是**文件绝对字节偏移**,可直接对照 `xxd line1.stb`
|
||||
- 映像里**没有符号名**(函数表只有 fn_id,数据段无名字映射),因此按 `fn 0` / `fn 1`、槽号显示
|
||||
- `model=` 显示型号标识(`machine.toml [meta]` 生成);`sha=ok|BAD` 显示文件尾 SHA-256 校验结果
|
||||
- 文件损坏或打不开 → `error: ...` 退出码 1
|
||||
|
||||
## 编译产物(.stb 加固)
|
||||
|
||||
- **型号标识[32]**:`[meta] name + version` 拼成(如 `"STATOR1"`),写进头偏移 72
|
||||
- **SHA-256 文件尾[32]**:对文件尾之前全部内容计算;compiler 写侧与 vm 读侧各实现一份
|
||||
- 执行器读取时型号不匹配 / SHA 不符 → 直接拒绝(详见 `Doc/isa/指令与映像.md` 12.13 修订)
|
||||
|
||||
## 示例(line1)
|
||||
|
||||
```bash
|
||||
@@ -65,11 +72,11 @@ files:
|
||||
main.st
|
||||
hash: 0xc3fe4ae74ad45900
|
||||
|
||||
$ STCompiler examples/line1/project.toml -o line1.stb
|
||||
compiled: line1.stb (184 bytes, 2 functions, 4 globals)
|
||||
$ STCompiler examples/line1/project.toml -o line1.stb --machine compiler/machine.toml
|
||||
compiled: line1.stb (288 bytes, 2 functions, 4 globals)
|
||||
```
|
||||
|
||||
产物 `line1.stb`:魔数 `STSC` + 版本 1 的单一映像(指令见 `Doc/isa/指令与映像.md`)。
|
||||
产物:`line1.stb`(288 字节:头 104 含型号标识 + 各段 + SHA-256 文件尾)+ `line1.runtime.toml`(sidecar)。指令见 `Doc/isa/指令与映像.md`,结构拆解见 `Doc/isa/stb文件格式.md`。
|
||||
|
||||
## 工程文件(project.toml)
|
||||
|
||||
@@ -142,10 +149,10 @@ project.toml + .st
|
||||
|
||||
- `examples/line1/`:最小闭环(MAIN + MotorStarter FB + I/O + 全局),给人看
|
||||
- `tests/cases/01~20/`:20 个用例(每份 `project.toml` + `.st` + `EXPECTED.md`),编译结果按表
|
||||
- `tests/`:CTest(`isa_roundtrip` / `compiler_toml` / `lexer_tokens` / `parser_syntax` / `linker_links` / `typecheck_types` / `codegen_slice1`)
|
||||
- `tests/`:CTest(`compiler_toml` / `lexer_tokens` / `parser_syntax` / `linker_links` / `typecheck_types` / `codegen_slice1` / `machine_config` / `vm_cycles` / `cases_all` / `cli_*`)
|
||||
|
||||
## 当前状态
|
||||
|
||||
- ✅ 可编译:14 个正例用例全部产出 `.stb`;6 个负例按期望拒绝
|
||||
- ⏳ 执行:`BytecodeExecutor`(加载 `.stb` 跑扫描周期)在 12.9/12.10
|
||||
- ⏳ sidecar(`<name>.runtime.toml`,I/O 绑定)在 12.10 随执行器一起接线
|
||||
- ✅ 可编译:14 个正例用例全部产出 `.stb`(含型号标识 + SHA-256);6 个负例按期望拒绝
|
||||
- ✅ 执行:`BytecodeExecutor` 加载 `.stb` 跑扫描周期(型号/SHA 校验、回放、单步)
|
||||
- ✅ 配置驱动:指令 opcode / 类型元数据 / FB 布局来自 `compiler/machine.toml`(`--machine`)
|
||||
|
||||
Reference in New Issue
Block a user