power_insn: convert spans into properties
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 09:29:55 +0000 (12:29 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:16 +0000 (19:51 +0100)
src/openpower/decoder/power_insn.py
src/openpower/sv/sv_binutils_fptrans.py

index f0ac37141a1a4235432bc2ef9f7d765dcf55a6eb..9217ceb910133f02b1cedacecda8abbfb6112592 100644 (file)
@@ -688,7 +688,7 @@ class Record:
 
             for (cls, kwargs) in self.mdwn.operands.static:
                 operand = cls(record=self, **kwargs)
-                for (src, dst) in enumerate(reversed(operand.span(record=self))):
+                for (src, dst) in enumerate(reversed(operand.span)):
                     value[dst] = int((operand.value & (1 << src)) != 0)
                     mask[dst] = 1
 
@@ -773,11 +773,12 @@ class Operand:
     record: Record
     name: str
 
-    def span(self, record):
-        return record.fields[self.name]
+    @cached_property
+    def span(self):
+        return self.record.fields[self.name]
 
     def assemble(self, value, insn, record):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         if isinstance(value, str):
@@ -795,7 +796,7 @@ class Operand:
 class DynamicOperand(Operand):
     def disassemble(self, insn, record,
             verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -818,7 +819,7 @@ class SignedOperand(DynamicOperand):
 
     def disassemble(self, insn, record,
             verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -842,7 +843,7 @@ class StaticOperand(Operand):
 
     def disassemble(self, insn, record,
             verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -878,7 +879,7 @@ class NonZeroOperand(DynamicOperand):
 
     def disassemble(self, insn, record,
             verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -902,7 +903,7 @@ class ExtendableOperand(DynamicOperand):
 
     def spec(self, insn, record):
         vector = False
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -1058,11 +1059,12 @@ class EXTSOperand(DynamicOperand):
         if not self.field:
             object.__setattr__(self, "field", self.name)
 
-    def span(self, record):
-        return record.fields[self.field]
+    @cached_property
+    def span(self):
+        return self.record.fields[self.field]
 
     def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -1111,14 +1113,16 @@ class EXTSOperandDQ(EXTSOperand, ImmediateOperand):
 
 @_dataclasses.dataclass(eq=True, frozen=True)
 class DOperandDX(SignedOperand):
-    def span(self, record):
-        operands = map(DynamicOperand, ("d0", "d1", "d2"))
-        spans = map(lambda operand: operand.span(record=record), operands)
+    @cached_property
+    def span(self):
+        cls = lambda name: DynamicOperand(name=name)
+        operands = map(cls, ("d0", "d1", "d2"))
+        spans = map(lambda operand: operand.span, operands)
         return sum(spans, tuple())
 
     def disassemble(self, insn, record,
             verbosity=Verbosity.NORMAL, indent=""):
-        span = self.span(record=record)
+        span = self.span
         if isinstance(insn, SVP64Instruction):
             span = tuple(map(lambda bit: (bit + 32), span))
         value = insn[span]
@@ -1132,7 +1136,7 @@ class DOperandDX(SignedOperand):
             }
             for (subname, subspan) in mapping.items():
                 operand = DynamicOperand(name=subname)
-                span = operand.span(record=record)
+                span = operand.span
                 if isinstance(insn, SVP64Instruction):
                     span = tuple(map(lambda bit: (bit + 32), span))
                 value = insn[span]
index b249e52c2b7db128cb3335ed9a5bcdcec3ae650d..9e89c5a7edbf5e60f28c431a49a8eed48e1af7f5 100644 (file)
@@ -82,13 +82,15 @@ def collect(db):
 
         @_dataclasses.dataclass(eq=True, frozen=True)
         class POStaticOperand(_StaticOperand):
-            def span(self, record):
+            @property
+            def span(self):
                 return tuple(range(0, 6))
 
         @_dataclasses.dataclass(eq=True, frozen=True)
         class XOStaticOperand(_StaticOperand):
-            def span(self, record):
-                return tuple(record.section.bitsel)
+            @property
+            def span(self):
+                return tuple(self.record.section.bitsel)
 
         static_operands = [(POStaticOperand, {
             "name": "PO",
@@ -107,13 +109,13 @@ def collect(db):
             (cls, kwargs) = operand
             operand = cls(record=record, **kwargs)
             return StaticOperand(name=operand.name,
-                value=operand.value, span=operand.span(record=record))
+                value=operand.value, span=operand.span)
 
         def dynamic_operand(operand):
             (cls, kwargs) = operand
             operand = cls(record=record, **kwargs)
             return DynamicOperand(name=operand.name,
-                span=operand.span(record=record))
+                span=operand.span)
 
         static_operands = tuple(map(static_operand, static_operands))
         dynamic_operands = tuple(map(dynamic_operand, dynamic_operands))