svp64.py: generate registers
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 30 Jun 2022 13:11:25 +0000 (16:11 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Wed, 6 Jul 2022 17:06:33 +0000 (20:06 +0300)
src/openpower/sv/sv_binutils.py

index fa59f273db4ba96f0d22ba261bec3c5d1ad3aa66..baa8241233432e70cd827eef0f923c9649997862 100644 (file)
@@ -2,6 +2,7 @@ import abc as _abc
 import argparse as _argparse
 import dataclasses as _dataclasses
 import enum as _enum
+import functools as _functools
 import operator as _operator
 
 from openpower.decoder.power_enums import (
@@ -519,6 +520,14 @@ class Codegen(_enum.Enum):
                         prefix="extern const ", suffix=";")
             yield ""
 
+            yield "extern const struct powerpc_pd_reg svp64_regs[];"
+            yield Size.c_var("svp64_num_regs", prefix="extern const ", suffix=";")
+            yield ""
+
+            yield "extern const struct powerpc_pd_reg svp64_cr_regs[];"
+            yield Size.c_var("svp64_num_cr_regs", prefix="extern const ", suffix=";")
+            yield ""
+
             yield "#ifdef __cplusplus"
             yield "}"
             yield "#endif"
@@ -655,6 +664,48 @@ class Codegen(_enum.Enum):
                 yield f"#undef {name}"
             yield ""
 
+            yield "const struct powerpc_pd_reg svp64_regs[] = {"
+            regs = {}
+            for (category, count, flags) in sorted((
+                        ("r", 128, "PPC_OPERAND_GPR"),
+                        ("f", 128, "PPC_OPERAND_FPR"),
+                        ("cr", 128, "PPC_OPERAND_CR_REG"),
+                    )):
+                for index in range(count):
+                    regs[f"{category}{index}"] = (index, flags)
+                    regs[f"{category}.{index}"] = (index, flags)
+            for (name, (index, flags)) in sorted(regs.items()):
+                yield from indent([f"{{\"{name}\", {index}, {flags}}},"])
+            yield "};"
+            yield ""
+
+            num_regs = Size("(sizeof (svp64_regs) / sizeof (svp64_regs[0]))")
+            yield Size.c_var("svp64_num_regs",
+                        prefix="const ", suffix=" = \\")
+            yield from indent(num_regs.c_value(suffix=";"))
+            yield ""
+
+            yield "const struct powerpc_pd_reg svp64_cr_regs[] = {"
+            regs = {
+                "eq": (2, "PPC_OPERAND_CR_BIT"),
+                "gt": (1, "PPC_OPERAND_CR_BIT"),
+                "lt": (0, "PPC_OPERAND_CR_BIT"),
+                "so": (3, "PPC_OPERAND_CR_BIT"),
+                "un": (3, "PPC_OPERAND_CR_BIT"),
+            }
+            for index in range(128):
+                regs[f"cr{index}"] = (index, "PPC_OPERAND_CR_REG")
+            for (name, (index, flags)) in sorted(regs.items()):
+                yield from indent([f"{{\"{name}\", {index}, {flags}}},"])
+            yield "};"
+            yield ""
+
+            num_regs = Size("(sizeof (svp64_cr_regs) / sizeof (svp64_cr_regs[0]))")
+            yield Size.c_var("svp64_num_cr_regs",
+                        prefix="const ", suffix=" = \\")
+            yield from indent(num_regs.c_value(suffix=";"))
+            yield ""
+
 
         records = Record[...](records)
         num_records = Size("(sizeof (svp64_records) / sizeof (svp64_records[0]))")