From: Dmitry Selyutin Date: Fri, 12 Aug 2022 13:32:32 +0000 (+0300) Subject: sv_binutils: support opcodes X-Git-Tag: sv_maxu_works-initial~143 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=22ca050c74776579736c54615ee987657aa4c36c;p=openpower-isa.git sv_binutils: support opcodes --- diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index 19e28262..2785b71e 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -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):