import operator as _operator
import pathlib as _pathlib
import re as _re
+import sys as _sys
try:
from functools import cached_property
_SVExtraReg.FRTp,
)
- def __init__(self, insn, iterable):
+ def __init__(self, insn, operands):
custom_insns = {
"b": {"target_addr": TargetAddrOperandLI},
"ba": {"target_addr": TargetAddrOperandLI},
"addpcis": {"D": DOperandDX},
"fishmv": {"D": DOperandDX},
"fmvis": {"D": DOperandDX},
+
+ # FIXME: these instructions are broken according to the specs.
+ # The operands in the assembly syntax are FRT,FRA,FRC,FRB.
+ # The real assembly order, however, is FRT,FRA,FRB,FRC.
+ # The legacy assembler placed operands in syntax order.
+ "ffmadds": {"FRB": FMAOperandFRB, "FRC": FMAOperandFRC},
+ "ffmadds.": {"FRB": FMAOperandFRB, "FRC": FMAOperandFRC},
+ "fdmadds": {"FRB": FMAOperandFRB, "FRC": FMAOperandFRC},
+ "fdmadds.": {"FRB": FMAOperandFRB, "FRC": FMAOperandFRC},
}
custom_fields = {
"SVi": NonZeroOperand,
}
mapping = {}
- for operand in iterable:
+ for operand in operands:
cls = DynamicOperand
if "=" in operand:
cls = custom_insns[insn][name]
elif name in custom_fields:
cls = custom_fields[name]
-
- if name in _SVExtraReg.__members__:
+ elif name in _SVExtraReg.__members__:
reg = _SVExtraReg[name]
if reg in self.__class__.__GPR_PAIRS:
cls = GPRPairOperand
class Arguments(tuple):
- def __new__(cls, arguments, operands):
- arguments = iter(tuple(arguments))
+ def __new__(cls, record, arguments, operands):
operands = iter(tuple(operands))
+ arguments = iter(tuple(arguments))
items = []
while True:
class XOStaticOperand(SpanStaticOperand):
def __init__(self, record, value, span):
+ if record.name == "ffadds":
+ print(value, span)
+
bits = record.section.bitsel
value = _SelectableInt(value=value, bits=len(bits))
span = dict(zip(bits, range(len(bits))))
style=style, indent=indent)
+class RedirectedOperand(DynamicOperand):
+ def __init__(self, record, name, target):
+ self.__target = target
+ return super().__init__(record=record, name=name)
+
+ @cached_property
+ def span(self):
+ print(f"{self.record.name}: {self.name} => {self.__target}", file=_sys.stderr)
+ return self.record.fields[self.__target]
+
+
+class FMAOperandFRB(RedirectedOperand, FPROperand):
+ def __init__(self, record, name):
+ return super().__init__(record=record, name=name, target="FRC")
+
+
+class FMAOperandFRC(RedirectedOperand, FPROperand):
+ def __init__(self, record, name):
+ return super().__init__(record=record, name=name, target="FRB")
+
+
class FPRPairOperand(FPROperand):
pass
for operand in cls.static_operands(record=record):
operand.assemble(insn=insn)
- dynamic_operands = tuple(cls.dynamic_operands(record=record))
- for (value, operand) in Arguments(arguments, dynamic_operands):
+ arguments = Arguments(record=record,
+ arguments=arguments, operands=cls.dynamic_operands(record=record))
+ for (value, operand) in arguments:
operand.assemble(insn=insn, value=value)
return insn
operands.extend(dynamic)
operands.extend(static)
pcode = PCode(iterable=desc.pcode)
- operands = Operands(insn=name, iterable=operands)
+ operands = Operands(insn=name, operands=operands)
db[name] = MarkdownRecord(pcode=pcode, operands=operands)
self.__db = dict(sorted(db.items()))