From: Dmitry Selyutin Date: Wed, 20 Apr 2022 10:56:29 +0000 (+0000) Subject: sv_binutils: generate entries and num_entries via classes X-Git-Tag: sv_maxu_works-initial~473 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ea16958e8fd1e6303ad3f5057839e17b069b5d2e;p=openpower-isa.git sv_binutils: generate entries and num_entries via classes --- diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index 24dfe2b0..73669963 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -345,7 +345,7 @@ class Codegen(_enum.Enum): }[self] def generate(self, entries): - def ppc_svp64_h(entries): + def ppc_svp64_h(entries, num_entries): yield from DISCLAIMER yield "" @@ -381,8 +381,8 @@ class Codegen(_enum.Enum): yield f"svp64_record_{name}_opsel(const struct svp64_record *record);" yield "" - yield "extern const struct svp64_entry svp64_entries[];" - yield "extern const unsigned int svp64_num_entries;" + yield from entries.__class__.c_var("svp64_entries", prefix="extern const ", suffix=";") + yield from num_entries.__class__.c_var("svp64_num_entries", prefix="extern const ", suffix=";") yield "" yield f"#define SVP64_NAME_MAX {max(map(lambda entry: len(entry.name), entries))}" @@ -396,7 +396,7 @@ class Codegen(_enum.Enum): yield f"#endif /* {self.name} */" yield "" - def ppc_svp64_opc_c(entries): + def ppc_svp64_opc_c(entries, num_entries): yield from DISCLAIMER yield "" @@ -463,20 +463,20 @@ class Codegen(_enum.Enum): CROutSel.WHOLE_REG: "FXM", }) - yield "const struct svp64_entry svp64_entries[] = {" - for (index, entry) in enumerate(entries): - yield from indent(entry.c_value(prefix=f"[{index}] = ", suffix=",")) - yield f"}};" + yield from entries.__class__.c_var("svp64_entries", prefix="const ", suffix=" = \\") + yield from entries.c_value(prefix="", suffix=";") yield "" - - yield "const unsigned int svp64_num_entries = \\" - yield " sizeof (svp64_entries) / sizeof (svp64_entries[0]);" + yield from num_entries.__class__.c_var("svp64_num_entries", prefix="const ", suffix=" = \\") + yield from indent(num_entries.c_value(suffix=";")) yield "" + entries = Entry[...](entries) + num_entries = Size("(sizeof (svp64_entries) / sizeof (svp64_entries[0])") + return { Codegen.PPC_SVP64_H: ppc_svp64_h, Codegen.PPC_SVP64_OPC_C: ppc_svp64_opc_c, - }[self](entries) + }[self](entries, num_entries) ISA = _SVP64RM()