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
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):
yield f"{prefix}{self.c_tag.upper()}_{self.c_name.upper()}{suffix}"
-Mode = Constant("Mode", _SVP64MODE)
+ModeConst = Constant("Mode", _SVP64MODE)
class StructMeta(ObjectMeta):
yield from super().c_decl()
yield ""
- for (path, field) in _SVP64Instruction.traverse(path="svp64_insn"):
+ for (path, field) in _SVP64Instruction.traverse(path=""):
yield from getter(path, field)
yield from setter(path, field)
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
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):
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}"
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()
yield from disclaimer.splitlines()
yield ""
+ yield "#include <stdbool.h>"
yield "#include \"opcode/ppc-svp64.h\""
yield ""
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",
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, Extra):
+ value = tuple(value)
+ if not value:
+ value = cls["NONE"]
+ else:
+ value = cls[value[0].name]
+ elif issubclass(cls, _enum.Enum):
value = cls[value.name]
else:
value = cls(value)