sv_binutils: undefine temporary macros
authorDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Mon, 25 Apr 2022 19:40:32 +0000 (19:40 +0000)
committerDmitry Selyutin <dmitry.selyutin@3mdeb.com>
Mon, 25 Apr 2022 19:40:32 +0000 (19:40 +0000)
src/openpower/sv/sv_binutils.py

index 352507e70a3578eefefc094bd5e86c2ff33f47d1..1775aa963f994d9b861e4108cad034db4811eeea 100644 (file)
@@ -2,6 +2,7 @@ import abc as _abc
 import argparse as _argparse
 import dataclasses as _dataclasses
 import enum as _enum
+import operator as _operator
 
 from openpower.decoder.power_enums import (
     In1Sel as _In1Sel,
@@ -568,21 +569,33 @@ class Codegen(_enum.Enum):
             bit_and = lambda lhs, rhs: f"({lhs} & {rhs})"
             bit_not = lambda val: f"~({val})"
 
-            macros = {
-                "CLEAR(VALUE, BIT)":
+            macros = (
+                (
+                    "SVP64_FIELD_CLEAR",
+                    ("VALUE", "BIT"),
                     bit_and("VALUE", bit_not(bit_shl("UINT32_C(1)", "BIT"))),
-                "REMAP(VALUE, SRC, DST)":
+                ),
+                (
+                    "SVP64_FIELD_REMAP",
+                    ("VALUE", "SRC", "DST"),
                     bit_shl(bit_get("VALUE", "SRC"), "DST"),
-                "GET(ORIGIN, SRC, DST)":
+                ),
+                (
+                    "SVP64_FIELD_GET",
+                    ("ORIGIN", "SRC", "DST"),
                     "SVP64_FIELD_REMAP(ORIGIN, SRC, DST)",
-                "SET(RESULT, VALUE, SRC, DST)":
+                ),
+                (
+                    "SVP64_FIELD_SET",
+                    ("RESULT", "VALUE", "SRC", "DST"),
                     " = ".join(["*(RESULT)", bit_or(
                         lhs="SVP64_FIELD_CLEAR(*(RESULT), DST)",
                         rhs="SVP64_FIELD_REMAP(VALUE, SRC, DST)",
                     )]),
-            }
-            for (call, body) in macros.items():
-                yield f"#define SVP64_FIELD_{call} \\"
+                ),
+            )
+            for (name, args, body) in macros:
+                yield f"#define {name}({', '.join(args)}) \\"
                 yield from indent([body])
                 yield ""
 
@@ -592,6 +605,10 @@ class Codegen(_enum.Enum):
                     yield from subcls.c_value()
                     yield ""
 
+            for name in map(_operator.itemgetter(0), macros):
+                yield f"#undef {name}"
+            yield ""
+
 
         entries = Entry[...](entries)
         num_entries = Size("(sizeof (svp64_entries) / sizeof (svp64_entries[0]))")