temporary hack-revert, the original is now in branch "paths"
[openpower-isa.git] / src / openpower / sv / sv_binutils.py
index 6ace71b20e7b5cb08c51919c6f8e35e394c72341..a6a7f10922f7f865955d43ca1188f772b2109eb3 100644 (file)
@@ -15,15 +15,15 @@ from openpower.decoder.power_enums import (
     CRInSel as _CRInSel,
     CRIn2Sel as _CRIn2Sel,
     CROutSel as _CROutSel,
-    SVPtype as _SVPtype,
-    SVEtype as _SVEtype,
+    SVPType as _SVPType,
+    SVEType as _SVEType,
     SVExtra as _SVExtra,
-    Function as _Function,
+    SVMode as _SVMode,
     find_wiki_dir as _find_wiki_dir,
 )
 from openpower.consts import SVP64MODE as _SVP64MODE
-from openpower.decoder.power_insn import Database as _Database
-from openpower.decoder.power_insn import SVP64Instruction as _SVP64Instruction
+from openpower.insndb.core import Database as _Database
+from openpower.insndb.core import SVP64Instruction as _SVP64Instruction
 
 
 DISCLAIMER = """\
@@ -181,10 +181,10 @@ OutSel = Enum("OutSel", _OutSel, c_tag="svp64_out_sel")
 CRInSel = Enum("CRInSel", _CRInSel, c_tag="svp64_cr_in_sel")
 CRIn2Sel = Enum("CRIn2Sel", _CRIn2Sel, c_tag="svp64_cr_in2_sel")
 CROutSel = Enum("CROutSel", _CROutSel, c_tag="svp64_cr_out_sel")
-PType = Enum("PType", _SVPtype, c_tag="svp64_ptype")
-EType = Enum("EType", _SVEtype, c_tag="svp64_etype", exclude="NONE")
+PType = Enum("PType", _SVPType, c_tag="svp64_ptype")
+EType = Enum("EType", _SVEType, c_tag="svp64_etype", exclude="NONE")
 Extra = Enum("Extra", _SVExtra, c_tag="svp64_extra", exclude="Idx_1_2")
-Function = Enum("Function", _Function, c_tag="svp64_function")
+Mode = Enum("Mode", _SVMode, c_tag="svp64_mode")
 
 
 class Constant(_enum.Enum, metaclass=EnumMeta):
@@ -201,7 +201,7 @@ class Constant(_enum.Enum, metaclass=EnumMeta):
         yield f"{prefix}{self.c_tag.upper()}_{self.c_name.upper()}{suffix}"
 
 
-Mode = Constant("Mode", _SVP64MODE)
+ModeConst = Constant("Mode", _SVP64MODE)
 
 
 class StructMeta(ObjectMeta):
@@ -320,7 +320,7 @@ class Instruction(Struct, c_tag="svp64_insn"):
 
         yield from super().c_decl()
         yield ""
-        for (path, field) in _SVP64Instruction.traverse():
+        for (path, field) in _SVP64Instruction.traverse(path=""):
             yield from getter(path, field)
             yield from setter(path, field)
 
@@ -338,9 +338,41 @@ class Name(Object, str, c_typedef="const char *"):
         return f"{prefix}const char *{name}{suffix}"
 
 
+class BooleanMeta(ObjectMeta):
+    def __len__(cls):
+        return 1
+
+
+class Boolean(Object, metaclass=BooleanMeta):
+    def __init__(self, value):
+        self.__state = bool(value)
+        return super().__init__()
+
+    def __bool__(self):
+        return self.__state
+
+    def __repr__(self):
+        return self.__state.__repr__()
+
+    @property
+    def name(self):
+        return "true" if self else "false"
+
+    @property
+    def value(self):
+        return "true" if self else "false"
+
+    def c_value(self, *, prefix="", suffix="", **kwargs):
+        yield f"{prefix}{self.value}{suffix}"
+
+    @classmethod
+    def c_var(cls, name, prefix="", suffix=""):
+        return f"{prefix}bool {name}{suffix}"
+
+
 @_dataclasses.dataclass(eq=True, frozen=True)
 class Desc(Struct):
-    function: Function
+    mode: Mode
     in1: In1Sel
     in2: In2Sel
     in3: In3Sel
@@ -357,7 +389,9 @@ class Desc(Struct):
     extra_idx_out: Extra
     extra_idx_out2: Extra
     extra_idx_cr_in: Extra
+    extra_idx_cr_in2: Extra
     extra_idx_cr_out: Extra
+    Rc: Boolean
 
     @classmethod
     def c_decl(cls):
@@ -396,6 +430,9 @@ class Opcodes(Object, c_typedef="const struct svp64_opcode *"):
         self.__offset = offset
         return super().__init__()
 
+    def __repr__(self):
+        return f"{self.__class__.__name__}({self.__offset})"
+
     @classmethod
     def c_var(cls, name, prefix="", suffix=""):
         return f"{prefix}{cls.c_typedef}{name}{suffix}"
@@ -450,9 +487,9 @@ class Codegen(_enum.Enum):
 
             enums = (
                 In1Sel, In2Sel, In3Sel, OutSel,
-                CRInSel, CROutSel,
+                CRInSel, CRIn2Sel, CROutSel,
                 PType, EType, Extra,
-                Mode, Function,
+                Mode, ModeConst,
             )
             for enum in enums:
                 yield from enum.c_decl()
@@ -491,6 +528,7 @@ class Codegen(_enum.Enum):
             yield from disclaimer.splitlines()
             yield ""
 
+            yield "#include <stdbool.h>"
             yield "#include \"opcode/ppc-svp64.h\""
             yield ""
 
@@ -540,13 +578,18 @@ class Codegen(_enum.Enum):
                     OutSel.RT_OR_ZERO: "RT",
                     OutSel.FRT: "FRT",
                     OutSel.FRS: "FRS",
+                    OutSel.RS: "RS",
                 })
             yield from opindex(CRInSel, "cr_in", {
                 CRInSel.BI: "BI",
                 CRInSel.BFA: "BFA",
                 CRInSel.BC: "BC",
+                CRInSel.BA: "BA",
                 CRInSel.WHOLE_REG: "FXM",
             })
+            yield from opindex(CRIn2Sel, "cr_in2", {
+                CRIn2Sel.BB: "BB",
+            })
             yield from opindex(CROutSel, "cr_out", {
                 CROutSel.BF: "BF",
                 CROutSel.BT: "BT",
@@ -614,12 +657,14 @@ def collect(db):
         for (key, cls) in fields.items():
             value = getattr(insn, key)
 
-            if (((cls is EType) and (value is _SVEtype.NONE)) or
+            if (((cls is EType) and (value is _SVEType.NONE)) or
                     ((cls is Extra) and (value is _SVExtra.Idx_1_2))):
                 desc = None
                 break
 
-            if issubclass(cls, _enum.Enum):
+            if issubclass(cls, Boolean):
+                value = Boolean(value)
+            elif issubclass(cls, _enum.Enum):
                 value = cls[value.name]
             else:
                 value = cls(value)