import dataclasses as _dataclasses
import enum as _enum
import functools as _functools
-import operator as _operator
+
from openpower.decoder.power_enums import (
FPTRANS_INSNS as _FPTRANS_INSNS,
- Enum,
find_wiki_dir as _find_wiki_dir,
)
-from openpower.decoder.selectable_int import (
- SelectableInt as _SelectableInt,
-)
from openpower.decoder.power_insn import (
Database as _Database,
StaticOperand as _StaticOperand,
return f"{{{string}}},"
-def asm(entry):
- for (idx, operand) in enumerate(entry.dynamic_operands):
- values = ([0] * len(entry.dynamic_operands))
- values[idx] = ((1 << len(operand.span)) - 1)
- return f"{entry.name} {','.join(map(str, values))}"
-
-
-def dis(entry):
+def asm(entry, binutils=False, regex=False):
+ operands = tuple(entry.dynamic_operands)
+ for (idx, operand) in enumerate(operands):
+ values = []
+ for each in operands:
+ if binutils and each.name in ("FRT", "FRA", "FRB"):
+ values.append("f0")
+ elif binutils and each.name in ("RT", "RA", "RB"):
+ values.append("r0")
+ else:
+ values.append("0")
+ value = str((1 << len(operand.span)) - 1)
+ if binutils and operand.name in ("FRT", "FRA", "FRB"):
+ value = f"f{value}"
+ elif binutils and operand.name in ("RT", "RA", "RB"):
+ value = f"r{value}"
+ values[idx] = value
+ sep = "\s+" if regex else " "
+ yield f"{entry.name}{sep}{','.join(values)}"
+
+
+def dis(entry, binutils=True):
def objdump(byte):
return f"{byte:02x}"
- for dynamic_operand in entry.dynamic_operands:
+ asm_plain = tuple(asm(entry, binutils=binutils, regex=False))
+ asm_regex = tuple(asm(entry, binutils=binutils, regex=True))
+ for (idx, dynamic_operand) in enumerate(entry.dynamic_operands):
insn = _WordInstruction.integer(value=0)
for static_operand in entry.static_operands:
span = static_operand.span
insn[span] = static_operand.value
span = dynamic_operand.span
insn[span] = ((1 << len(span)) - 1)
- big = " ".join(map(objdump, insn.bytes(byteorder="big")))
- little = " ".join(map(objdump, insn.bytes(byteorder="little")))
- return f".*\t({big}|{little}) \t{asm(entry)}"
+ if binutils:
+ big = " ".join(map(objdump, insn.bytes(byteorder="big")))
+ little = " ".join(map(objdump, insn.bytes(byteorder="little")))
+ yield f".*:\s+({big}|{little})\s+{asm_regex[idx]}"
+ else:
+ yield asm_plain[idx]
class Mode(_enum.Enum):
print(".*: file format .*")
print("")
print("")
-
- for line in map(generator, entries):
- print(line)
+ print("Disassembly of section \\.text:")
+ print("0+ <\.text>:")
+
+ if mode in {Mode.ASM, Mode.DIS}:
+ for subgenerator in map(generator, entries):
+ for line in subgenerator:
+ print(line)
+ else:
+ for line in map(generator, entries):
+ print(line)