From: Dmitry Selyutin Date: Tue, 19 Apr 2022 22:28:59 +0000 (+0000) Subject: sv_binutils: introduce Integer class X-Git-Tag: sv_maxu_works-initial~484 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a2da9aba92fa77c267be854988ffa4e05f20c429;p=openpower-isa.git sv_binutils: introduce Integer class --- diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index 3f3692ea..6b0a9776 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -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 " + + 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