步骤 1:OpFormat/OpClass 显式化 + disasm 表驱动。
- Op.h:新增 OpFormat(RR/RRR/IMM/SLOT/JMP/JC/CALL/CAL/NONE)与 OpClass(Plain/Instance)枚举;34 条编译期表 kOpDefs(name/format/class, 与 ops.txt 强校验的基准);mnemonic/format/op_class 查表 - Encode.cpp:disasm 按 format 表驱动输出(文本与之前逐条一致) - 验证:11 个 ctest 全绿;表查询断言(8 个 INSTANCE=CAL、越界哨兵)
This commit is contained in:
+11
-38
@@ -38,61 +38,34 @@ void disasm(Instr w, char* out, size_t cap) {
|
||||
}
|
||||
const char* m = mnemonic(o);
|
||||
|
||||
switch (o) {
|
||||
case Op::MOVE:
|
||||
case Op::NOT:
|
||||
// 表驱动:按操作数形态输出(文本与 Doc/isa/指令与映像.md 一致)
|
||||
switch (format(o)) {
|
||||
case OpFormat::RR:
|
||||
snprintf(out, cap, "%s r%u, r%u", m,
|
||||
static_cast<unsigned>(rd(w)), static_cast<unsigned>(a(w)));
|
||||
break;
|
||||
case Op::AND:
|
||||
case Op::OR:
|
||||
case Op::ADD:
|
||||
case Op::SUB:
|
||||
case Op::MUL:
|
||||
case Op::DIV:
|
||||
case Op::CMP_EQ:
|
||||
case Op::CMP_NE:
|
||||
case Op::CMP_LT:
|
||||
case Op::CMP_LE:
|
||||
case Op::CMP_GT:
|
||||
case Op::CMP_GE:
|
||||
case OpFormat::RRR:
|
||||
snprintf(out, cap, "%s r%u, r%u, r%u", m,
|
||||
static_cast<unsigned>(rd(w)), static_cast<unsigned>(a(w)),
|
||||
static_cast<unsigned>(b(w)));
|
||||
break;
|
||||
case Op::LOADK:
|
||||
case OpFormat::IMM:
|
||||
case OpFormat::SLOT:
|
||||
snprintf(out, cap, "%s r%u, %u", m,
|
||||
static_cast<unsigned>(rd(w)), static_cast<unsigned>(imm16(w)));
|
||||
break;
|
||||
case Op::JMP:
|
||||
case OpFormat::JMP:
|
||||
snprintf(out, cap, "%s %+d", m, static_cast<int>(off16(w)));
|
||||
break;
|
||||
case Op::JT:
|
||||
case Op::JF:
|
||||
case OpFormat::JC:
|
||||
snprintf(out, cap, "%s r%u, %+d", m,
|
||||
static_cast<unsigned>(rd(w)), static_cast<int>(off16(w)));
|
||||
break;
|
||||
case Op::LOAD_I:
|
||||
case Op::STORE_Q:
|
||||
case Op::LOAD_M:
|
||||
case Op::STORE_M:
|
||||
case Op::LOAD_GLOBAL:
|
||||
case Op::STORE_GLOBAL:
|
||||
snprintf(out, cap, "%s r%u, %u", m,
|
||||
static_cast<unsigned>(rd(w)), static_cast<unsigned>(imm16(w)));
|
||||
break;
|
||||
case Op::CAL_TON:
|
||||
case Op::CAL_TOF:
|
||||
case Op::CAL_TP:
|
||||
case Op::CAL_CTU:
|
||||
case Op::CAL_CTD:
|
||||
case Op::CAL_CTUD:
|
||||
case Op::CAL_R_TRIG:
|
||||
case Op::CAL_F_TRIG:
|
||||
case Op::CALL:
|
||||
case OpFormat::CALL:
|
||||
case OpFormat::CAL:
|
||||
snprintf(out, cap, "%s %u", m, static_cast<unsigned>(imm16(w)));
|
||||
break;
|
||||
case Op::RET:
|
||||
case OpFormat::NONE:
|
||||
snprintf(out, cap, "%s", m);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user