12.10 双可执行接线:编译产出 sidecar,BytecodeExecutor 跑周期。

- STCompiler -o:另写 <name>.runtime.toml(io 绑定 var→槽号→channel/bit,槽号来自链接结果)
- BytecodeExecutor <name>.stb [--cycles N] [--replay <file>]:加载 .stb + sidecar,
  逐周期采样 I(回放行按 io.input 顺序)→ 跑周期 → 打印 I/Q;故障打印 FAULT 退出码 1
- 手写 sidecar 解析(冻结 TOML 子集);Machine 暴露 header()(dt_ms/cycle_limit)
- 验证:line1 回放 0/1 组合 Q 正确(急停/start 语义)、用例 06 CycleLimit FAULT;ctest 10/10
This commit is contained in:
2026-08-21 20:26:28 +08:00
parent 8c0fc4fe98
commit 00565f035d
5 changed files with 267 additions and 4 deletions
+23
View File
@@ -5,8 +5,10 @@
* @date 2026-08-21
*/
#include <cctype>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <string>
#include <vector>
@@ -167,6 +169,27 @@ int main(int argc, char** argv) {
return 1;
}
// sidecarI/O 绑定 var → 槽号 → channel/bit(不进映像,执行器采样用)
std::vector<isa::IoBinding> bindings;
for (const isa::IoBinding& b : proj.io) {
isa::IoBinding out_b = b;
std::string key = b.var;
for (char& ch : key) {
ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
}
const auto it = link.global_index.find(key);
if (it != link.global_index.end()) {
out_b.slot = it->second; // 12.6 已校验存在
}
bindings.push_back(out_b);
}
std::filesystem::path sidecar = std::filesystem::path(out_path);
sidecar.replace_extension(".runtime.toml");
if (!isa::write_sidecar_file(sidecar.string().c_str(), bindings, &err)) {
std::fprintf(stderr, "error: %s\n", err.c_str());
return 1;
}
const isa::ImageView v = isa::ImageView::from(image);
std::printf("compiled: %s (%zu bytes, %u functions, %u globals)\n",
out_path.c_str(), image.size(), v.header().n_funcs, v.header().n_globals);