def HandleOneInstruction(count: int, line: str, data: int, ins: Ins, actual_name: str, actual_ops: List[str]): name, ops_str = symbolic.InsSymbolize(ins) ins2 = symbolic.InsFromSymbolized(name, ops_str) assert tuple(ins.operands) == tuple(ins2.operands), f"{ins.operands} vs {ins2.operands}" MassageOperandsAndCheckName(actual_name, ins.opcode, actual_ops) assert OperandsMatch(ins.opcode, ops_str, actual_ops), f"[{name}] mismatch in [{count}]: {ops_str} vs {actual_ops}: {line}"
def disass(data): ins = a64.Disassemble(data) if ins is None: print(f"could not disassemble {data:x}") return enum_name, ops_str = symbolic.InsSymbolize(ins) print(f"{data:08x}", f"{ins.opcode.NameForEnum()} {' '.join(ops_str)}") for f, o, o_str in zip(ins.opcode.fields, ins.operands, ops_str): print(f" {f.name:35s} {o_str:10} ({o})") # print(f"flags: {ins.opcode.classes}") print() data2 = a64.Assemble(ins) assert data == data2 ins2 = symbolic.InsFromSymbolized(enum_name, ops_str) assert tuple(ins.operands) == tuple( ins2.operands), f"{ins.operands} vs {ins2.operands}"
def batch(): for line in sys.stdin: if not line or line.startswith("#"): continue data = int(line.split()[0], 16) ins = a64.Disassemble(data) if ins.opcode is None: print(f"could not disassemble {data:x}") continue enum_name, ops_str = symbolic.InsSymbolize(ins) print( f"{data:08x} {enum_name}{' ' if ops_str else ''}{', '.join(ops_str)}" ) data2 = a64.Assemble(ins) assert data == data2 ins2 = symbolic.InsFromSymbolized(enum_name, ops_str) assert tuple(ins.operands) == tuple( ins2.operands), f"{ins.operands} vs {ins2.operands}"
def HandleIns(ins: ir.Ins, ctx: regs.EmitContext): print("INS: " + serialize.InsRenderToAsm(ins).strip() + f" [{' '.join(OpTypeStr(o) for o in ins.operands)}]") if ins.opcode in isel_tab.OPCODES_REQUIRING_SPECIAL_HANDLING: print(f" SPECIAL") return mismatches = isel_tab.FindtImmediateMismatchesInBestMatchPattern( ins, False) if mismatches == isel_tab.MATCH_IMPOSSIBLE: print(f" MATCH_IMPOSSIBLE") elif mismatches != 0: pattern = isel_tab.FindMatchingPattern(ins) assert pattern is None print(f" mismatches: {mismatches:x}") else: pattern = isel_tab.FindMatchingPattern(ins) print( f"PAT: reg:[{' '.join(a.name for a in pattern.type_constraints)}] " f"imm:[{' '.join(a.name for a in pattern.imm_curbs)}]") for tmpl in pattern.emit: armins = tmpl.MakeInsFromTmpl(ins, ctx) name, ops = symbolic.InsSymbolize(armins) print(f" {name} {' '.join(ops)}")
def _RenderIns(ins: a64.Ins) -> str: name, ops = symbolic.InsSymbolize(ins) return f" {name} {' '.join(ops)}"