power_insn: unify GPR and FPR assembly
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 6 Nov 2022 17:06:41 +0000 (20:06 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 15 Jan 2023 19:47:22 +0000 (22:47 +0300)
src/openpower/decoder/power_insn.py

index 89dbbda850725721c97fbdd905196ed68fa90f19..158c11abf590fedb983953a87a78e38ebb18a312 100644 (file)
@@ -1135,15 +1135,31 @@ class ExtendableOperand(DynamicOperand):
 
 
 @_dataclasses.dataclass(eq=True, frozen=True)
-class GPROperand(ExtendableOperand):
-    def assemble(self, value, insn):
+class SimpleRegisterOperand(ExtendableOperand):
+    def assemble(self, value, insn, prefix):
+        vector = False
+
         if isinstance(value, str):
             value = value.lower()
-            if value.startswith("r"):
+            if value.startswith("%"):
+                value = value[1:]
+            if value.startswith("*"):
+                if not isinstance(insn, SVP64Instruction):
+                    raise ValueError(value)
                 value = value[1:]
+                vector = True
+            if value.startswith(prefix):
+                value = value[len(prefix):]
             value = int(value, 0)
+
         return super().assemble(value=value, insn=insn)
 
+
+@_dataclasses.dataclass(eq=True, frozen=True)
+class GPROperand(SimpleRegisterOperand):
+    def assemble(self, value, insn):
+        return super().assemble(value=value, insn=insn, prefix="r")
+
     def disassemble(self, insn,
             verbosity=Verbosity.NORMAL, indent=""):
         prefix = "" if (verbosity <= Verbosity.SHORT) else "r"
@@ -1152,14 +1168,9 @@ class GPROperand(ExtendableOperand):
 
 
 @_dataclasses.dataclass(eq=True, frozen=True)
-class FPROperand(ExtendableOperand):
+class FPROperand(SimpleRegisterOperand):
     def assemble(self, value, insn):
-        if isinstance(value, str):
-            value = value.lower()
-            if value.startswith("f"):
-                value = value[1:]
-            value = int(value, 0)
-        return super().assemble(value=value, insn=insn)
+        return super().assemble(value=value, insn=insn, prefix="f")
 
     def disassemble(self, insn,
             verbosity=Verbosity.NORMAL, indent=""):