From bbb9a98c167268964cdfa35269f4463d0a5bc63e Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 23 Sep 2022 00:49:46 +0300 Subject: [PATCH] sv_binutils: provide Boolean class and Rc field --- src/openpower/sv/sv_binutils.py | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index 76f5753e..7fa7d949 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -338,6 +338,38 @@ class Name(Object, str, c_typedef="const char *"): return f"{prefix}const char *{name}{suffix}" +class BooleanMeta(ObjectMeta): + def __len__(cls): + return 1 + + +class Boolean(Object, metaclass=BooleanMeta): + def __init__(self, value): + self.__state = bool(value) + return super().__init__() + + def __bool__(self): + return self.__state + + def __repr__(self): + return self.__state.__repr__() + + @property + def name(self): + return "true" if self else "false" + + @property + def value(self): + return "true" if self else "false" + + def c_value(self, *, prefix="", suffix="", **kwargs): + yield f"{prefix}{self.value}{suffix}" + + @classmethod + def c_var(cls, name, prefix="", suffix=""): + return f"{prefix}bool {name}{suffix}" + + @_dataclasses.dataclass(eq=True, frozen=True) class Desc(Struct): mode: Mode @@ -359,6 +391,7 @@ class Desc(Struct): extra_idx_cr_in: Extra extra_idx_cr_in2: Extra extra_idx_cr_out: Extra + Rc: Boolean @classmethod def c_decl(cls): @@ -495,6 +528,7 @@ class Codegen(_enum.Enum): yield from disclaimer.splitlines() yield "" + yield "#include " yield "#include \"opcode/ppc-svp64.h\"" yield "" @@ -627,7 +661,9 @@ def collect(db): desc = None break - if issubclass(cls, _enum.Enum): + if issubclass(cls, Boolean): + value = Boolean(value) + elif issubclass(cls, _enum.Enum): value = cls[value.name] else: value = cls(value) -- 2.30.2