def dump_fancy(self): for i, bs in enumerate(self.instructions): data = struct.unpack("<I", bs)[0] ins = a32.Disassemble(data) _, ops = dis.InsSymbolize(ins) if ops and ops[0] == "al": ops.pop(0) print( f"{i:2d} {[f'{b:02x}' for b in bs]} {data:08x} {ins.opcode.name} {' '.join(ops)}" )
def disass(data): ins = a32.Disassemble(data) if ins.opcode is None: print(f"could not disassemble {data:x}") return enum_name, operands_str = symbolic.InsSymbolize(ins) print(f"{data:08x} {enum_name} {', '.join(operands_str)}") for f, o, o_str in zip(ins.opcode.fields, ins.operands, operands_str): print(f" {f.name:25} {o_str:15} ({o})") print() data2 = a32.Assemble(ins) assert data == data2 ins2 = symbolic.InsFromSymbolized(enum_name, operands_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 = a32.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 = a32.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 HandleOneInstruction(count: int, line: str, data: int, actual_name: str, actual_ops: List): ins = a32.Disassemble(data) assert ins is not None, f"cannot disassemble [{count}]: {line}" assert ins.opcode is not None and ins.operands is not None, f"unknown opcode {line}" data2 = a32.Assemble(ins) assert data == data2, f"disass mismatch [{ins.opcode.NameForEnum()}] {data:x} vs {data2:x}" actual_name = FixupAliases(ins.opcode, actual_name, actual_ops) if not actual_name.startswith(ins.opcode.official_name): print("BAD NAME", ins.opcode.name, actual_name, line, end="") name, operands_str = symbolic.InsSymbolize(ins) if not OperandsMatch(ins.opcode, actual_name, actual_ops, operands_str): print(f"OPERANDS differ {operands_str} {actual_ops} in line {line}", end="") ins2 = symbolic.InsFromSymbolized(name, operands_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) 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_constraints)}]") for tmpl in pattern.emit: armins = tmpl.MakeInsFromTmpl(ins, ctx) name, ops = symbolic.InsSymbolize(armins) print(f" {name} {' '.join(ops)}")
def _RenderIns(ins: a32.Ins): name, ops = symbolic.InsSymbolize(ins) return f" {name} {' '.join(ops)}"