阶段2-6:V2 生成侧 bug 修复与验证收尾
- Codec:set_byte0 的 11/10 前缀位修正(0xC0/0x80);新增 JC 形态偏移 专用读写(off@55..24,字节 3..6)——修复 JF rd 被 off 覆盖 - Stb:offset_meta=0(空段)时值段大小校验按 SHA 尾计算(修复 values segment size mismatch) - Codegen:实例字段带 func(field_func),LOAD_OFF/STORE_OFF 按字段 类型设 func(pt=TIME → I64) - main.cpp:--disasm 按 instr_len 迭代变长字节码 - 验证:13 个正例全部编译出 V2 产物 + disasm 自读通过(RET/CAL.TON/ STORE_OFF.I64/JF 偏移等抽查正确);ctest 11/13(vm/cases 待阶段 4)
This commit is contained in:
+24
-4
@@ -121,7 +121,7 @@ uint32_t imm32_of(const uint8_t* code) {
|
||||
uint32_t slot32_of(const uint8_t* code) { return imm32_of(code); }
|
||||
|
||||
/**
|
||||
* @brief 取 off32(47..16,小端 4 字节,有符号)。
|
||||
* @brief 取 off32(47..16,JMP 形态,小端 4 字节,有符号)。
|
||||
* @param code 指令字节
|
||||
* @return 字节偏移(相对下一条)
|
||||
*/
|
||||
@@ -132,6 +132,18 @@ int32_t off32_of(const uint8_t* code) {
|
||||
| (static_cast<uint32_t>(code[5]) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 取 off32(55..24,JC 形态,小端 4 字节,有符号)。
|
||||
* @param code 指令字节
|
||||
* @return 字节偏移(相对下一条)
|
||||
*/
|
||||
int32_t off32_jc_of(const uint8_t* code) {
|
||||
return static_cast<int32_t>(static_cast<uint32_t>(code[3])
|
||||
| (static_cast<uint32_t>(code[4]) << 8)
|
||||
| (static_cast<uint32_t>(code[5]) << 16)
|
||||
| (static_cast<uint32_t>(code[6]) << 24));
|
||||
}
|
||||
|
||||
uint32_t fn_id32_of(const uint8_t* code) {
|
||||
return static_cast<uint32_t>(code[2])
|
||||
| (static_cast<uint32_t>(code[3]) << 8)
|
||||
@@ -193,9 +205,9 @@ uint64_t imm64_of(const uint8_t* code) {
|
||||
*/
|
||||
void set_byte0(uint8_t* out, const std::string& prefix, uint32_t op) {
|
||||
if (prefix == "11") {
|
||||
out[0] = static_cast<uint8_t>(0x80 | (op & 0x3F));
|
||||
out[0] = static_cast<uint8_t>(0xC0 | (op & 0x3F)); // bit7..6 = 11
|
||||
} else if (prefix == "10") {
|
||||
out[0] = static_cast<uint8_t>(0x80 | 0x40 | (op & 0x3F));
|
||||
out[0] = static_cast<uint8_t>(0x80 | (op & 0x3F)); // bit7..6 = 10
|
||||
} else if (prefix == "011") {
|
||||
out[0] = static_cast<uint8_t>(0x40 | (op & 0x1F));
|
||||
} else if (prefix.size() == 6 && prefix.compare(0, 3, "010") == 0) {
|
||||
@@ -232,6 +244,14 @@ void set_off32(uint8_t* out, int32_t v) {
|
||||
out[4] = static_cast<uint8_t>((u >> 16) & 0xFF);
|
||||
out[5] = static_cast<uint8_t>((u >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
void set_off32_jc(uint8_t* out, int32_t v) {
|
||||
const uint32_t u = static_cast<uint32_t>(v);
|
||||
out[3] = static_cast<uint8_t>(u & 0xFF);
|
||||
out[4] = static_cast<uint8_t>((u >> 8) & 0xFF);
|
||||
out[5] = static_cast<uint8_t>((u >> 16) & 0xFF);
|
||||
out[6] = static_cast<uint8_t>((u >> 24) & 0xFF);
|
||||
}
|
||||
void set_fn_id32(uint8_t* out, uint32_t v) { set_off32(out, static_cast<int32_t>(v)); }
|
||||
void set_fb_id16(uint8_t* out, uint16_t v) {
|
||||
out[2] = static_cast<uint8_t>(v & 0xFF);
|
||||
@@ -302,7 +322,7 @@ void disasm(const MachineConfig& cfg, const uint8_t* code, size_t len,
|
||||
snprintf(out, cap, "%s %+d", op->name.c_str(), static_cast<int>(off32_of(code)));
|
||||
} else if (f == "JC") {
|
||||
snprintf(out, cap, "%s r%u, %+d", op->name.c_str(),
|
||||
static_cast<unsigned>(rd_of(code)), static_cast<int>(off32_of(code)));
|
||||
static_cast<unsigned>(rd_of(code)), static_cast<int>(off32_jc_of(code)));
|
||||
} else if (f == "CALL") {
|
||||
snprintf(out, cap, "%s %u", op->name.c_str(), static_cast<unsigned>(fn_id32_of(code)));
|
||||
} else if (f == "CAL") {
|
||||
|
||||
Reference in New Issue
Block a user