sv_binutils: support opcodes
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Aug 2022 13:32:32 +0000 (16:32 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Aug 2022 19:07:43 +0000 (22:07 +0300)
src/openpower/sv/sv_binutils.py

index 19e282628aaed0b334ff5784678b945e97aa7cbd..2785b71e56e80fa173ae5b57d78d03085c0ec036 100644 (file)
@@ -281,6 +281,24 @@ class Name(CType, str, typedef="const char *"):
         return f"{prefix}const char *{name}{suffix}"
 
 
+@_dataclasses.dataclass(eq=True, frozen=True)
+class Opcode(Struct):
+    class Value(UInt32):
+        def __new__(cls, value):
+            if isinstance(value, int):
+                value = f"0x{value:08x}"
+            return super().__new__(cls, value)
+
+    class Mask(UInt32):
+        def __new__(cls, value):
+            if isinstance(value, int):
+                value = f"0x{value:08x}"
+            return super().__new__(cls, value)
+
+    value: Value
+    mask: Mask
+
+
 @_dataclasses.dataclass(eq=True, frozen=True)
 class Desc(Struct):
     in1: In1Sel
@@ -317,6 +335,7 @@ class Desc(Struct):
 @_dataclasses.dataclass(eq=True, frozen=True)
 class Record(Struct):
     name: Name
+    opcode: Opcode
     desc: Desc
 
     def __lt__(self, other):
@@ -511,7 +530,7 @@ class Codegen(_enum.Enum):
                 yield from enum.c_decl()
                 yield ""
 
-            for cls in (Desc, Record, Prefix, RM):
+            for cls in (Desc, Opcode, Record, Prefix, RM):
                 yield from cls.c_decl()
                 yield ""
 
@@ -719,9 +738,12 @@ def records(db):
             continue
 
         name = Name(insn.name)
+        value = Opcode.Value(insn.opcode.value)
+        mask = Opcode.Mask(insn.opcode.mask)
+        opcode = Opcode(value=value, mask=mask)
         desc = Desc(**desc)
 
-        yield Record(name=name, desc=desc)
+        yield Record(name=name, opcode=opcode, desc=desc)
 
 
 def main(codegen):