sv_binutils: generate entries and num_entries via classes
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Wed, 20 Apr 2022 10:56:29 +0000 (10:56 +0000)
committerDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Wed, 20 Apr 2022 12:26:43 +0000 (12:26 +0000)
src/openpower/sv/sv_binutils.py

index 24dfe2b0b420a88a5e0757cd643abb040d17fe92..736699634ab1384578be5901a22c5a178b86c2f6 100644 (file)
@@ -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()