12.9 步骤 0:数据段改 8 字节定宽槽(方案 a)。
- 指令与映像.md / 寄存器码.md:slot 语义 = 槽号(数据偏移 = 槽号 × 8),取消变宽对齐与 global_offset 映射 - Codegen.cpp:删除 width_of/align_up/global_offsets_;layout_data/layout_fb_instances 按槽号布局(字段 = 槽序号) - stb文件格式.md:line1 真实字节更新(224B、56B 数据段、starter 槽 4/5/6) - codegen_test:断言更新(槽号化 + 数据区字节数),189 断言 9/9 全绿
This commit is contained in:
+17
-17
@@ -174,7 +174,7 @@ static bool test_case09() {
|
||||
const isa::ImageView v = isa::ImageView::from(img);
|
||||
CHECK(v.ok());
|
||||
CHECK(v.header().n_globals == 1);
|
||||
CHECK(v.data_len() == 2); // INT 2 字节
|
||||
CHECK(v.data_len() == 8); // 8 字节定宽槽
|
||||
CHECK(v.data_bytes()[0] == 5); // G1 初值 5(小端低位)
|
||||
CHECK(v.data_bytes()[1] == 0);
|
||||
|
||||
@@ -248,14 +248,14 @@ static bool test_layout() {
|
||||
const isa::ImageView v = isa::ImageView::from(img);
|
||||
CHECK(v.ok());
|
||||
CHECK(v.header().n_globals == 3);
|
||||
CHECK(v.data_len() == 16); // 0 + 2 + 8(对齐)= 16
|
||||
CHECK(v.data_len() == 24); // 3 槽 × 8 字节定宽
|
||||
CHECK(v.data_bytes()[0] == 0); // B 无初值
|
||||
CHECK(v.data_bytes()[2] == 0x2C && v.data_bytes()[3] == 0x01); // I = 300
|
||||
CHECK(v.data_bytes()[8] == 10); // T = 10ms
|
||||
CHECK(v.data_bytes()[8] == 0x2C && v.data_bytes()[9] == 0x01); // I = 300(槽 1)
|
||||
CHECK(v.data_bytes()[16] == 10); // T = 10ms(槽 2)
|
||||
|
||||
char buf[64];
|
||||
isa::disasm(reinterpret_cast<const uint32_t*>(v.code_bytes())[0], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 2") == 0); // x := I(INT 偏移 2)
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 1") == 0); // x := I(槽 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ static bool test_case15() {
|
||||
CHECK(v.ok());
|
||||
CHECK(v.header().n_funcs == 2); // FB 占位 + MAIN
|
||||
CHECK(v.header().entry_fn_id == 1);
|
||||
CHECK(v.data_len() == 8); // 实例 3B(start@0 stop@1 q@2),8 对齐
|
||||
CHECK(v.data_len() == 24); // 实例 3 槽 × 8 字节定宽
|
||||
|
||||
const isa::FuncRow fm = v.func_row(1);
|
||||
CHECK(fm.nregs == 12);
|
||||
@@ -602,11 +602,11 @@ static bool test_case17() {
|
||||
isa::disasm(ins[2], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOADK r10, 1") == 0);
|
||||
isa::disasm(ins[3], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r10, 8") == 0); // pt(TIME 8 对齐)
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r10, 1") == 0); // pt(槽 1)
|
||||
isa::disasm(ins[4], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "CAL_TON 0") == 0);
|
||||
isa::disasm(ins[5], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 16") == 0); // t.Q
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 2") == 0); // t.Q(槽 2)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ static bool test_case18() {
|
||||
|
||||
const isa::ImageView v = isa::ImageView::from(img);
|
||||
CHECK(v.ok());
|
||||
CHECK(v.data_len() == 40); // tf 块 0..31(in@0 pt@8 q@16 et@24)、c 块 32..
|
||||
CHECK(v.data_len() == 72); // tf 4 槽 + c 5 槽 = 9 槽 × 8
|
||||
const isa::FuncRow r = v.func_row(0);
|
||||
CHECK(r.nregs == 14);
|
||||
const uint32_t* ins = reinterpret_cast<const uint32_t*>(v.code_bytes());
|
||||
@@ -627,11 +627,11 @@ static bool test_case18() {
|
||||
isa::disasm(ins[4], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "CAL_TOF 0") == 0);
|
||||
isa::disasm(ins[12], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "CAL_CTU 32") == 0);
|
||||
CHECK(std::strcmp(buf, "CAL_CTU 4") == 0);
|
||||
isa::disasm(ins[13], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r9, 36") == 0); // c.Q
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r9, 7") == 0); // c.Q(槽 7)
|
||||
isa::disasm(ins[14], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r10, 38") == 0); // c.CV(INT 2 对齐)
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r10, 8") == 0); // c.CV(槽 8)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ static bool test_line1() {
|
||||
CHECK(v.header().n_globals == 4);
|
||||
CHECK(v.header().n_funcs == 2);
|
||||
CHECK(v.header().entry_fn_id == 1);
|
||||
CHECK(v.data_len() == 16); // 全局 4B + 实例块 8..10(8 对齐)
|
||||
CHECK(v.data_len() == 56); // 7 槽 × 8 字节定宽
|
||||
|
||||
const isa::FuncRow fm = v.func_row(1);
|
||||
CHECK(fm.nregs == 13);
|
||||
@@ -670,15 +670,15 @@ static bool test_line1() {
|
||||
isa::disasm(im[0], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_I r8, 1") == 0); // I0_0(io.input)
|
||||
isa::disasm(im[1], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r8, 8") == 0); // starter.start
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r8, 4") == 0); // starter.start(槽 4)
|
||||
isa::disasm(im[2], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r9, 2") == 0); // I0_1
|
||||
isa::disasm(im[3], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r9, 9") == 0); // starter.stop
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r9, 5") == 0); // starter.stop(槽 5)
|
||||
isa::disasm(im[13], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r8, 10") == 0); // starter.Q
|
||||
CHECK(std::strcmp(buf, "STORE_GLOBAL r8, 6") == 0); // starter.Q(槽 6)
|
||||
isa::disasm(im[14], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 10") == 0); // starter.Q 读回
|
||||
CHECK(std::strcmp(buf, "LOAD_GLOBAL r8, 6") == 0); // starter.Q 读回
|
||||
isa::disasm(im[15], buf, sizeof buf);
|
||||
CHECK(std::strcmp(buf, "STORE_Q r8, 3") == 0); // Q0_0(io.output)
|
||||
isa::disasm(im[16], buf, sizeof buf);
|
||||
|
||||
Reference in New Issue
Block a user