From a2da9aba92fa77c267be854988ffa4e05f20c429 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 19 Apr 2022 22:28:59 +0000 Subject: [PATCH] sv_binutils: introduce Integer class --- src/openpower/sv/sv_binutils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 -- 2.30.2