阶段 C 步骤 7:isa 拆出 Image,vm 依赖收窄。

- 删 isa/Image.h + Image.cpp(ImageView/FNV/写文件/sidecar 不再属于 isa)
- vm 自实现只读视图 vm/Image.h/cpp:头 104(12.13)/段校验/缺 SHA 尾报错
  (型号匹配与 SHA 校验留步骤 8);Machine 改用 vm::Image + vm::ImageHeader
- executor:本地读文件(替换 isa::read_stb_file)
- 测试:isa_test 删映像/FNV 部分;codegen_test/vm_test 改用 compiler::StbView /
  vm::ConstEntry;vm_test 手拼映像适配新格式(头 104 + 尾 32 占位)
- 验证:line1 编译 288 字节 → BytecodeExecutor 回放 Q 正确;ctest 12/12
This commit is contained in:
2026-08-21 22:24:57 +08:00
parent a308ae713d
commit 5fccbadaa8
12 changed files with 334 additions and 647 deletions
+12 -13
View File
@@ -15,7 +15,6 @@
#include "compiler/Project.h"
#include "compiler/Typecheck.h"
#include "isa/Encode.h"
#include "isa/Image.h"
#include "isa/Instr.h"
#include "isa/Op.h"
#include "vm/Machine.h"
@@ -93,7 +92,7 @@ struct HFunc {
uint32_t nregs = 8;
};
static std::vector<uint8_t> hand_image(const std::vector<isa::ConstEntry>& consts,
static std::vector<uint8_t> hand_image(const std::vector<vm::ConstEntry>& consts,
const std::vector<HFunc>& funcs,
uint32_t entry = 0,
uint32_t cycle_limit = 100000,
@@ -102,11 +101,11 @@ static std::vector<uint8_t> hand_image(const std::vector<isa::ConstEntry>& const
for (const HFunc& f : funcs) {
code_total += f.code.size() * 4;
}
const uint32_t off_const = 72;
const uint32_t off_const = 104;
const uint32_t off_funcs = off_const + static_cast<uint32_t>(consts.size()) * 12;
const uint32_t off_code = off_funcs + static_cast<uint32_t>(funcs.size()) * 12;
const uint32_t off_data = off_code + static_cast<uint32_t>(code_total);
const uint32_t off_end = off_data + static_cast<uint32_t>(data.size());
const uint32_t off_end = off_data + static_cast<uint32_t>(data.size()) + 32; // SHA 尾占位
std::vector<uint8_t> b(off_end, 0);
auto put32 = [&](size_t o, uint32_t v) {
@@ -120,8 +119,8 @@ static std::vector<uint8_t> hand_image(const std::vector<isa::ConstEntry>& const
b[o + i] = static_cast<uint8_t>((v >> (8 * i)) & 0xFFu);
}
};
put32(0, isa::kMagic);
put32(4, isa::kVersion);
put32(0, 0x43545353u);
put32(4, 1u);
put32(8, cycle_limit);
put32(12, 10); // dt_ms
put32(24, entry);
@@ -163,10 +162,10 @@ static std::vector<uint8_t> hand_image(const std::vector<isa::ConstEntry>& const
static bool test_hand_scalar() {
// r8 := 5r9 := r8 + 3;槽 0 ← r9;槽 1 → r10;JT 跳过一条
const std::vector<isa::ConstEntry> consts = {
{isa::types::Int, 5},
{isa::types::Int, 3},
{isa::types::Int, 1},
const std::vector<vm::ConstEntry> consts = {
{1, 5},
{1, 3},
{1, 1},
};
const std::vector<HFunc> funcs = {{
{
@@ -201,9 +200,9 @@ static bool test_hand_scalar() {
static bool test_hand_call() {
// fn0(入口):r8=5、r2=7、实参 r1←r8CALL 1;结果 r0 → r8
// fn1r0 = r1 + r2r1/r2 来自调用约定区复制)
const std::vector<isa::ConstEntry> consts = {
{isa::types::Int, 5},
{isa::types::Int, 7},
const std::vector<vm::ConstEntry> consts = {
{1, 5},
{1, 7},
};
const std::vector<HFunc> funcs = {
{{