From: Dmitry Selyutin Date: Sun, 4 Sep 2022 09:49:42 +0000 (+0300) Subject: power_insn: inherit Operands from tuple X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f1865fb853155f6668af576480e5ccee0d59bc0b;p=openpower-isa.git power_insn: inherit Operands from tuple --- diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index a3226a81..83f1487a 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -443,6 +443,7 @@ class Operand: def disassemble(self, value, record, verbose=False): raise NotImplementedError + @_dataclasses.dataclass(eq=True, frozen=True) class DynamicOperand(Operand): def disassemble(self, value, record, verbose=False): @@ -454,6 +455,7 @@ class DynamicOperand(Operand): else: yield str(int(value)) + @_dataclasses.dataclass(eq=True, frozen=True) class StaticOperand(Operand): value: int @@ -467,6 +469,7 @@ class StaticOperand(Operand): else: yield str(int(value)) + @_dataclasses.dataclass(eq=True, frozen=True) class DynamicOperandTargetAddrLI(DynamicOperand): @property @@ -488,6 +491,7 @@ class DynamicOperandTargetAddrLI(DynamicOperand): yield hex(int(_selectconcat(value, _SelectableInt(value=0b00, bits=2)))) + class DynamicOperandTargetAddrBD(DynamicOperand): @property def name(self): @@ -508,6 +512,7 @@ class DynamicOperandTargetAddrBD(DynamicOperand): yield hex(int(_selectconcat(value, _SelectableInt(value=0b00, bits=2)))) + @_dataclasses.dataclass(eq=True, frozen=True) class DynamicOperandGPR(DynamicOperand): def disassemble(self, value, record, verbose=False): @@ -519,6 +524,7 @@ class DynamicOperandGPR(DynamicOperand): else: yield f"r{str(int(value))}" + @_dataclasses.dataclass(eq=True, frozen=True) class DynamicOperandFPR(DynamicOperand): def disassemble(self, value, record, verbose=False): @@ -531,8 +537,8 @@ class DynamicOperandFPR(DynamicOperand): yield f"f{str(int(value))}" -class Operands: - def __init__(self, insn, iterable): +class Operands(tuple): + def __new__(cls, insn, iterable): branches = { "b": {"target_addr": DynamicOperandTargetAddrLI}, "ba": {"target_addr": DynamicOperandTargetAddrLI}, @@ -574,21 +580,13 @@ class Operands: operand = dynamic_cls(name=operand) operands.append(operand) - self.__operands = operands - - return super().__init__() - - def __repr__(self): - return self.__operands.__repr__() - - def __iter__(self): - yield from self.__operands + return super().__new__(cls, operands) def __contains__(self, key): return self.__getitem__(key) is not None def __getitem__(self, key): - for operand in self.__operands: + for operand in self: if operand.name == key: return operand