文档同步双可执行架构:STCompiler + BytecodeExecutor。
- 12.10 重写为两条命令:STCompiler 编译出 .stb + sidecar,BytecodeExecutor 加载执行 - 12.0 删独立 stc.exe,12.13 依赖方向改为 STCompiler/BytecodeExecutor - 指令与映像.md 新增「映像文件(.stb)与 sidecar」节,I/O 绑定不进映像 - host/ 改名 executor/,宿主入口.md 重写为执行器入口.md - README / tests / examples / isa README 同步
This commit is contained in:
+19
-18
@@ -5,8 +5,8 @@
|
||||
`compiler` 写映像、`vm` 读映像,两边只依赖本目录,不互链。
|
||||
|
||||
```text
|
||||
host → compiler → isa
|
||||
host → vm → isa
|
||||
STCompiler → compiler → isa
|
||||
BytecodeExecutor → vm → isa
|
||||
```
|
||||
|
||||
**类型、操作码、指令字、映像布局以** [`doc/isa/指令与映像.md`](../doc/isa/指令与映像.md) **为准。** 头文件实现该文,本 README 不另当规范。全工程阶段见 [`doc/初步计划.md`](../doc/初步计划.md) 12.0~12.1。
|
||||
@@ -34,11 +34,11 @@ isa/
|
||||
CMakeLists.txt
|
||||
README.md
|
||||
include/isa/
|
||||
Types.hpp # 宽度、饱和、槽值
|
||||
Op.hpp # 操作码枚举 + 助记符声明
|
||||
Instr.hpp # 32-bit 打包/拆字段(inline)
|
||||
Encode.hpp # encode / decode / disasm
|
||||
Image.hpp # 头、段、FNV、读写缓冲
|
||||
Types.h # 宽度、饱和、槽值
|
||||
Op.h # 操作码枚举 + 助记符
|
||||
Instr.h # 32-bit 打包/拆字段(inline)
|
||||
Encode.h # encode / decode / disasm
|
||||
Image.h # 头、段、FNV、读写缓冲
|
||||
src/
|
||||
Encode.cpp
|
||||
Image.cpp
|
||||
@@ -55,13 +55,13 @@ target_include_directories(isa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
### 0. CMake 骨架
|
||||
|
||||
根 `CMakeLists.txt` 已 `add_subdirectory` 了 `compiler` / `vm` / `host`。这三个目录若没有 `CMakeLists.txt`,顶层 configure 失败,`isa` 也编不过。
|
||||
根 `CMakeLists.txt` 已 `add_subdirectory` 了 `compiler` / `vm` / `executor`。这三个目录若没有 `CMakeLists.txt`,顶层 configure 失败,`isa` 也编不过。
|
||||
|
||||
本步只让工程能配置、能链,不写业务。
|
||||
|
||||
- 写本目录 `CMakeLists.txt`(上面那段即可)
|
||||
- `compiler` / `vm`:空 `.cpp` + `PUBLIC` 链 `isa`
|
||||
- `host`:`main` 打印 `Stator 0.1`,链 `compiler`、`vm`
|
||||
- `executor`:`BytecodeExecutor`,`main` 打印版本,链 `vm`、`isa`;`STCompiler` 入口在 `compiler/src/main.cpp`,链 `compiler`、`isa`
|
||||
- 根 CMake:`enable_testing()`(测试文件下一步再加)
|
||||
|
||||
完成:`cmake --build` 过。
|
||||
@@ -86,11 +86,11 @@ target_include_directories(isa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
---
|
||||
|
||||
### 2. `Types.hpp`
|
||||
### 2. `Types.h`
|
||||
|
||||
`include/isa/Types.hpp`,inline,无对应 `.cpp`。命名空间 `isa`。C++11,不用 designated initializer。
|
||||
`include/isa/Types.h`,inline,无对应 `.cpp`。命名空间 `isa`。C++11,不用 designated initializer。
|
||||
|
||||
- `Bool` = `uint8_t`,`Int` = `int16_t`,`Time` = `int32_t`(毫秒)
|
||||
- `Bool` = `uint8_t`,`Int` = `int16_t`,`Time` = `int64_t`(毫秒;理由见规范文)
|
||||
- `TypeTag`:`Bool` / `Int` / `Time`
|
||||
- `sat_add` / `sat_sub` / `sat_mul` / `sat_div`(规则见规范文)
|
||||
- `pack_bool` / `pack_int` / `pack_time` → 4 字节 cell;对应 unpack
|
||||
@@ -99,18 +99,18 @@ target_include_directories(isa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
---
|
||||
|
||||
### 3. `Op.hpp` + `Instr.hpp`
|
||||
### 3. `Op.h` + `Instr.h`
|
||||
|
||||
- `Op.hpp`:`enum Op : uint8_t`,取值与规范文一致;声明 `op_mnemonic(Op)`(表可放 `Encode.cpp`)
|
||||
- `Instr.hpp`:`typedef uint32_t Instr`;`pack`、取 `op`/`rd`/`a`/`b`、`imm16`/`off16`;按形态 `enc_rr` / `enc_rrr` / `enc_imm` / `enc_jmp` / `enc_jc`
|
||||
- `Op.h`:`enum Op : uint8_t`,取值与规范文一致;`mnemonic(Op)` 助记符(已在头内落地)
|
||||
- `Instr.h`:`typedef uint32_t Instr`;`pack`、取 `op`/`rd`/`a`/`b`、`imm16`/`off16`;按形态 `enc_rr` / `enc_rrr` / `enc_imm` / `enc_jmp` / `enc_jc`
|
||||
|
||||
完成:能打包/拆开一条 32-bit 指令,不依赖 `.cpp`。
|
||||
|
||||
---
|
||||
|
||||
### 4. `Encode.hpp` + `Encode.cpp`
|
||||
### 4. `Encode.h` + `Encode.cpp`
|
||||
|
||||
给 host 打印和测试往返:
|
||||
给 `STCompiler --disasm` 和测试往返打印:
|
||||
|
||||
- `Decoded { Op op; uint8_t rd, a, b; }`
|
||||
- `Instr encode(Decoded)` / `Decoded decode(Instr)`
|
||||
@@ -122,12 +122,13 @@ target_include_directories(isa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
---
|
||||
|
||||
### 5. `Image.hpp` + `Image.cpp`
|
||||
### 5. `Image.h` + `Image.cpp`
|
||||
|
||||
- `fnv1a64` / `fnv1a64_update`
|
||||
- `ImageView`:只读视图,指向外部缓冲
|
||||
- `read_image`:校验魔数、版本、头大小、各段不越界、`entry_fn_id` 落在函数表内
|
||||
- `write_ret_main(cycle_limit, dt_ms, hash)` → `std::vector<uint8_t>`:空槽 + `MAIN` + 一条 `RET`
|
||||
- `.stb` 文件读写与 `<name>.runtime.toml` sidecar(I/O 绑定 var → 槽号 → channel/bit)
|
||||
|
||||
小端 `put_*` / `get_*` 只放 `.cpp`,不把 packed struct 当 ABI。本阶段不写完整 `ImageBuilder`(等 codegen)。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user