From 6f6fd955573fd778709051f4fbad948ef6ca8057 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 30 Dec 2021 17:45:10 +0000 Subject: [PATCH] sv_binutils: introduce code generator class --- src/openpower/sv/sv_binutils.py | 37 ++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index d3101c89..501a0aff 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -138,6 +138,36 @@ class Entry: yield f"struct svp64_entry {name};" +class Codegen(_enum.Enum): + PPC_OPC_SVP64_H = _enum.auto() + PPC_OPC_SVP64_C = _enum.auto() + + @classmethod + def _missing_(cls, value): + return { + "ppc-opc-svp64.h": Codegen.PPC_OPC_SVP64_H, + "ppc-opc-svp64.c": Codegen.PPC_OPC_SVP64_C, + }[value] + + def __str__(self): + return { + Codegen.PPC_OPC_SVP64_H: "ppc-opc-svp64.h", + Codegen.PPC_OPC_SVP64_C: "ppc-opc-svp64.c", + }[self] + + def generate(self, entries): + def ppc_opc_svp64_h(entries): + yield from () + + def ppc_opc_svp64_c(entries): + yield from () + + return { + Codegen.PPC_OPC_SVP64_H: ppc_opc_svp64_h, + Codegen.PPC_OPC_SVP64_C: ppc_opc_svp64_c, + }[self](entries) + + def regex_enum(enum): assert issubclass(enum, _enum.Enum) return "|".join(item.name for item in enum) @@ -199,14 +229,15 @@ def parse(stream): yield Entry(**entry) -def main(): +def main(codegen): entries = tuple(parse(_sys.stdin)) - - print(f"{len(entries)} entries found") + for line in codegen.generate(entries): + print(line) if __name__ == "__main__": parser = _argparse.ArgumentParser() + parser.add_argument("codegen", type=Codegen, choices=Codegen, help="code generator") args = vars(parser.parse_args()) main(**args) -- 2.30.2