from openpower.decoder.pseudo.pagereader import ISA as _ISA
+@_functools.total_ordering
+class Verbosity(_enum.Enum):
+ SHORT = _enum.auto()
+ NORMAL = _enum.auto()
+ VERBOSE = _enum.auto()
+
+ def __lt__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return (self.value < other.value)
+
+
def dataclass(cls, record, keymap=None, typemap=None):
if keymap is None:
keymap = {}
class Operand:
name: str
- def disassemble(self, insn, record, verbose=False, indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
raise NotImplementedError
@_dataclasses.dataclass(eq=True, frozen=True)
class DynamicOperand(Operand):
- def disassemble(self, insn, record, verbose=False, indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
span = record.fields[self.name]
if isinstance(insn, SVP64Instruction):
span = tuple(map(lambda bit: (bit + 32), span))
value = insn[span]
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
span = map(str, span)
yield f"{indent}{self.name}"
yield f"{indent}{indent}{int(value):0{value.bits}b}"
return _SVExtra.NONE
- def disassemble(self, insn, record, verbose=False, prefix="", indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, prefix="", indent=""):
(vector, value, span) = self.spec(insn=insn, record=record)
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
yield f"{indent}{self.name}"
yield f"{indent}{indent}{int(value):0{value.bits}b}"
yield f"{indent}{indent}{', '.join(span)}"
else:
etype = repr(record.etype).lower()
yield f"{indent}{indent}{etype}{extra_idx!r}"
+ yield f"{indent}type"
+ yield f"{indent}{indent}{'vector' if vector else 'scalar'}"
else:
vector = "*" if vector else ""
yield f"{vector}{prefix}{int(value)}"
class StaticOperand(Operand):
value: int
- def disassemble(self, insn, record, verbose=False, indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
span = record.fields[self.name]
if isinstance(insn, SVP64Instruction):
span = tuple(map(lambda bit: (bit + 32), span))
value = insn[span]
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
span = map(str, span)
yield f"{indent}{self.name}"
yield f"{indent}{indent}{int(value):0{value.bits}b}"
@_dataclasses.dataclass(eq=True, frozen=True)
class DynamicOperandTargetAddr(DynamicOperandReg):
- def disassemble(self, insn, record, field, verbose=False, indent=""):
+ def disassemble(self, insn, record, field,
+ verbosity=Verbosity.NORMAL, indent=""):
span = record.fields[field]
if isinstance(insn, SVP64Instruction):
span = tuple(map(lambda bit: (bit + 32), span))
value = insn[span]
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
span = tuple(map(str, span))
yield f"{indent}{self.name}"
yield f"{indent}{indent}{int(value):0{value.bits}b}00"
@_dataclasses.dataclass(eq=True, frozen=True)
class DynamicOperandTargetAddrLI(DynamicOperandTargetAddr):
- def disassemble(self, insn, record, verbose=False, indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
return super().disassemble(field="LI",
- insn=insn, record=record, verbose=verbose, indent=indent)
+ insn=insn, record=record,
+ verbosity=verbosity, indent=indent)
class DynamicOperandTargetAddrBD(DynamicOperandTargetAddr):
- def disassemble(self, insn, record, verbose=False, indent=""):
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
return super().disassemble(field="BD",
- insn=insn, record=record, verbose=verbose, indent=indent)
+ insn=insn, record=record,
+ verbosity=verbosity, indent=indent)
@_dataclasses.dataclass(eq=True, frozen=True)
class DynamicOperandGPR(DynamicOperandReg):
- def disassemble(self, insn, record, verbose=False, indent=""):
- yield from super().disassemble(prefix="r",
- insn=insn, record=record, verbose=verbose, indent=indent)
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
+ prefix = "" if (verbosity <= Verbosity.SHORT) else "r"
+ yield from super().disassemble(prefix=prefix,
+ insn=insn, record=record,
+ verbosity=verbosity, indent=indent)
@_dataclasses.dataclass(eq=True, frozen=True)
class DynamicOperandFPR(DynamicOperandReg):
- def disassemble(self, insn, record, verbose=False, indent=""):
- yield from super().disassemble(prefix="f",
- insn=insn, record=record, verbose=verbose, indent=indent)
+ def disassemble(self, insn, record,
+ verbosity=Verbosity.NORMAL, indent=""):
+ prefix = "" if (verbosity <= Verbosity.SHORT) else "f"
+ yield from super().disassemble(prefix=prefix,
+ insn=insn, record=record,
+ verbosity=verbosity, indent=indent)
class Operands(tuple):
return f"{prefix}{record.name}{operands}"
- def dynamic_operands(self, db):
+ def dynamic_operands(self, db, verbosity=Verbosity.NORMAL):
record = self.record(db=db)
imm = False
imm_value = ""
for operand in record.operands.dynamic:
name = operand.name
- value = " ".join(operand.disassemble(insn=self,
- record=record, verbose=False))
+ dis = operand.disassemble(insn=self, record=record,
+ verbosity=min(verbosity, Verbosity.NORMAL))
+ value = " ".join(dis)
if imm:
name = f"{imm_name}({name})"
value = f"{imm_value}({value})"
for operand in record.operands.static:
yield (operand.name, operand.value)
- def disassemble(self, db, byteorder="little", verbose=False):
+ def disassemble(self, db,
+ byteorder="little",
+ verbosity=Verbosity.NORMAL):
raise NotImplementedError
record = self.record(db=db)
return f"0x{record.opcode.mask:08x}"
- def disassemble(self, db, byteorder="little", verbose=False):
+ def disassemble(self, db,
+ byteorder="little",
+ verbosity=Verbosity.NORMAL):
integer = int(self)
- blob = integer.to_bytes(length=4, byteorder=byteorder)
- blob = " ".join(map(lambda byte: f"{byte:02x}", blob))
+ if verbosity <= Verbosity.SHORT:
+ blob = ""
+ else:
+ blob = integer.to_bytes(length=4, byteorder=byteorder)
+ blob = " ".join(map(lambda byte: f"{byte:02x}", blob))
+ blob += " "
record = self.record(db=db)
if record is None:
- yield f"{blob} .long 0x{integer:08x}"
+ yield f"{blob}.long 0x{integer:08x}"
return
operands = tuple(map(_operator.itemgetter(1),
- self.dynamic_operands(db=db)))
+ self.dynamic_operands(db=db, verbosity=verbosity)))
if operands:
- yield f"{blob} {record.name} {','.join(operands)}"
+ yield f"{blob}{record.name} {','.join(operands)}"
else:
- yield f"{blob} {record.name}"
+ yield f"{blob}{record.name}"
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
indent = (" " * 4)
binary = self.binary
spec = self.spec(db=db, prefix="")
yield f"{indent}mask"
yield f"{indent}{indent}{mask}"
for operand in record.operands:
- yield from operand.disassemble(insn=self,
- record=record, verbose=True, indent=indent)
+ yield from operand.disassemble(insn=self, record=record,
+ verbosity=verbosity, indent=indent)
yield ""
raise ValueError(self)
- def disassemble(self, db, byteorder="little", verbose=False):
- integer_prefix = int(self.prefix)
- blob_prefix = integer_prefix.to_bytes(length=4, byteorder=byteorder)
- blob_prefix = " ".join(map(lambda byte: f"{byte:02x}", blob_prefix))
-
- integer_suffix = int(self.suffix)
- blob_suffix = integer_suffix.to_bytes(length=4, byteorder=byteorder)
- blob_suffix = " ".join(map(lambda byte: f"{byte:02x}", blob_suffix))
+ def disassemble(self, db,
+ byteorder="little",
+ verbosity=Verbosity.NORMAL):
+ def blob(integer):
+ if verbosity <= Verbosity.SHORT:
+ return ""
+ else:
+ blob = integer.to_bytes(length=4, byteorder=byteorder)
+ blob = " ".join(map(lambda byte: f"{byte:02x}", blob))
+ return f"{blob} "
+ blob_prefix = blob(int(self.prefix))
+ blob_suffix = blob(int(self.suffix))
record = self.record(db=db)
if record is None or record.svp64 is None:
- yield f"{blob_prefix} .long 0x{int(self.prefix):08x}"
- yield f"{blob_suffix} .long 0x{int(self.suffix):08x}"
+ yield f"{blob_prefix}.long 0x{int(self.prefix):08x}"
+ yield f"{blob_suffix}.long 0x{int(self.suffix):08x}"
return
operands = tuple(map(_operator.itemgetter(1),
- self.dynamic_operands(db=db)))
+ self.dynamic_operands(db=db, verbosity=verbosity)))
if operands:
- yield f"{blob_prefix} sv.{record.name} {','.join(operands)}"
+ yield f"{blob_prefix}sv.{record.name} {','.join(operands)}"
else:
- yield f"{blob_prefix} {record.name}"
+ yield f"{blob_prefix}{record.name}"
yield f"{blob_suffix}"
(mode, mode_desc) = self.mode(db=db)
- if verbose:
+ if verbosity >= Verbosity.VERBOSE:
indent = (" " * 4)
binary = self.binary
spec = self.spec(db=db, prefix="sv.")
yield f"{indent}mask"
yield f"{indent}{indent}{mask}"
for operand in record.operands:
- yield from operand.disassemble(insn=self,
- record=record, verbose=True, indent=indent)
+ yield from operand.disassemble(insn=self, record=record,
+ verbosity=verbosity, indent=indent)
yield f"{indent}mode"
yield f"{indent}{indent}{mode_desc}"