power_insn: introduce operand disassembly
authorDmitry Selyutin <ghostmansd@gmail.com>
Wed, 31 Aug 2022 08:37:31 +0000 (11:37 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 2 Sep 2022 08:44:11 +0000 (11:44 +0300)
src/openpower/decoder/power_insn.py

index 512c74b5d017a87372b593fbbd22ac07d530ddd6..f90cc32d2b27dac8eb1c577faf715b3ba8a3c890 100644 (file)
@@ -4,7 +4,6 @@ import dataclasses as _dataclasses
 import enum as _enum
 import functools as _functools
 import os as _os
-import operator as _operator
 import pathlib as _pathlib
 import re as _re
 
@@ -409,17 +408,6 @@ class Operand:
     pass
 
 
-@_dataclasses.dataclass(eq=True, frozen=True)
-class DynamicOperand(Operand):
-    name: str
-
-
-@_dataclasses.dataclass(eq=True, frozen=True)
-class StaticOperand(Operand):
-    name: str
-    value: int = None
-
-
 class Operands(tuple):
     def __new__(cls, iterable):
         operands = []
@@ -434,6 +422,20 @@ class Operands(tuple):
         return super().__new__(cls, operands)
 
 
+@_dataclasses.dataclass(eq=True, frozen=True)
+class DynamicOperand(Operand):
+    name: str
+
+    def disassemble(self, value, record):
+        return str(int(value[record.fields[self.name]]))
+
+
+@_dataclasses.dataclass(eq=True, frozen=True)
+class StaticOperand(Operand):
+    name: str
+    value: int = None
+
+
 @_functools.total_ordering
 @_dataclasses.dataclass(eq=True, frozen=True)
 class Record:
@@ -618,10 +620,10 @@ class WordInstruction(Instruction):
         else:
             operands = []
             for operand in record.dynamic_operands:
-                operand = int(self[record.fields[operand.name]])
+                operand = operand.disassemble(self, record)
                 operands.append(operand)
             if operands:
-                operands = ",".join(map(str, operands))
+                operands = ",".join(operands)
                 operands = f" {operands}"
             else:
                 operands = ""