return map(lambda string: (" " + string), strings)
-class Field:
+class CType:
@classmethod
@_abc.abstractmethod
def c_decl(self, name):
pass
-class Enum(Field, _enum.Enum):
+class Enum(CType, _enum.Enum):
@classmethod
def c_decl(cls):
c_tag = f"svp64_{cls.__name__.lower()}"
SVEXTRA = Enum("SVEXTRA", {item.name:item.value for item in _SVEXTRA})
-class Opcode(Field):
+class Opcode(CType):
def __init__(self, value, mask, bits):
self.__value = value
self.__mask = mask
return super().__init__(value=value, mask=mask, bits=bits)
-class Name(Field, str):
+class Name(CType, str):
def __repr__(self):
escaped = self.replace("\"", "\\\"")
return f"\"{escaped}\""
@_dataclasses.dataclass(eq=True, frozen=True)
-class Entry(Field):
+class Entry(CType):
name: Name
opcode: Opcode
in1: In1Sel
yield f"#define {self.name}"
yield ""
+ yield "#include <stdint.h>"
+ yield ""
+
yield from Opcode.c_decl()
yield ""
yield from Entry.c_decl()
yield ""
+ yield "extern const struct svp64_entry svp64_entries[];"
+ yield "extern const unsigned int svp64_num_entries;"
+ yield ""
+
yield f"#endif /* {self.name} */"
yield ""
def ppc_opc_svp64_c(entries):
- yield from ()
+ yield from DISCLAIMER
+ yield ""
+
+ yield "#include \"ppc-opc-svp64.h\""
+ yield ""
+
+ 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 f"const unsigned int svp64_num_entries = {len(entries)};"
+ yield ""
return {
Codegen.PPC_OPC_SVP64_H: ppc_opc_svp64_h,
}
for (path, opcode_cls) in table.items():
entries.extend(parse(path, opcode_cls))
- entries = sorted(entries)
+ entries = sorted(frozenset(entries))
for line in codegen.generate(entries):
print(line)