sv_binutils: introduce Integer class
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Tue, 19 Apr 2022 22:28:59 +0000 (22:28 +0000)
committerDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Tue, 19 Apr 2022 22:28:59 +0000 (22:28 +0000)
src/openpower/sv/sv_binutils.py

index 3f3692eadd932e47867bf18376f9b3fe70c30c32..6b0a9776f682729209e5f458ca02741b9de45680 100644 (file)
@@ -144,6 +144,29 @@ class Struct(CType, metaclass=StructMeta):
         yield f"}}{suffix}"
 
 
+class IntegerMeta(CTypeMeta):
+    def __new__(metacls, name, bases, attrs, typedef=None):
+        cls = super().__new__(metacls, name, bases, attrs)
+        cls.__typedef = typedef
+
+        return cls
+
+    @property
+    def c_typedef(cls):
+        return cls.__typedef
+
+    def c_decl(cls):
+        yield "#include <stdint.h>"
+
+    def c_var(cls, name):
+        yield f"{cls.c_typedef} {name}"
+
+
+class Integer(CType, int, metaclass=IntegerMeta):
+    def c_value(self, prefix="", suffix=""):
+        yield f"{prefix}{self}{suffix}"
+
+
 class Opcode(CType):
     def __init__(self, value, mask, bits):
         self.__value = value