power_insn: introduce record operands helpers
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 09:29:55 +0000 (12:29 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 15 Jan 2023 19:47:22 +0000 (22:47 +0300)
src/openpower/decoder/power_insn.py

index 9217ceb910133f02b1cedacecda8abbfb6112592..130055110e13b0b3fe7a6e4a543087cb32f66361 100644 (file)
@@ -669,6 +669,16 @@ class Record:
         rhs = (min(other.opcodes), other.name)
         return (lhs < rhs)
 
+    @property
+    def static_operands(self):
+        for (cls, kwargs) in self.mdwn.operands.static:
+            yield cls(record=self, **kwargs)
+
+    @property
+    def dynamic_operands(self):
+        for (cls, kwargs) in self.mdwn.operands.dynamic:
+            yield cls(record=self, **kwargs)
+
     @property
     def opcodes(self):
         def opcode(ppc):
@@ -686,8 +696,7 @@ class Record:
                 value[dst] = int((XO.value & (1 << src)) != 0)
                 mask[dst] = int((XO.mask & (1 << src)) != 0)
 
-            for (cls, kwargs) in self.mdwn.operands.static:
-                operand = cls(record=self, **kwargs)
+            for operand in self.static_operands:
                 for (src, dst) in enumerate(reversed(operand.span)):
                     value[dst] = int((operand.value & (1 << src)) != 0)
                     mask[dst] = 1
@@ -1220,8 +1229,7 @@ class Instruction(_Mapping):
         imm = False
         imm_name = ""
         imm_value = ""
-        for (cls, kwargs) in record.mdwn.operands.dynamic:
-            operand = cls(record=record, **kwargs)
+        for operand in record.dynamic_operands:
             name = operand.name
             value = " ".join(operand.disassemble(insn=self,
                 record=record, verbosity=min(verbosity, Verbosity.NORMAL)))
@@ -1238,8 +1246,7 @@ class Instruction(_Mapping):
 
     def static_operands(self, db):
         record = self.record(db=db)
-        for (cls, kwargs) in record.mdwn.operands.static:
-            operand = cls(record=record, **kwargs)
+        for operand in record.static_operands:
             yield (operand.name, operand.value)
 
     @classmethod