+class Instruction(str):
+ def __new__(cls, string):
+ svp64 = False
+ if string.startswith("sv."):
+ string = string[len("sv."):]
+ svp64 = True
+ self = super().__new__(cls, string)
+ self.__svp64 = svp64
+ return self
+
+ @property
+ def svp64(self):
+ return self.__svp64
+
+
+class SVP64Instruction(Instruction):
+ def __new__(cls, string):
+ self = super().__new__(cls, string)
+ if not self.svp64:
+ raise ValueError("illegal SVP64 instruction")
+ return self
+
+
+class ListVisitor(Visitor):
+ @visitormethod(Record)
+ def Record(self, node):
+ print(node.name)
+ yield node
+
+
+class OpcodesVisitor(Visitor):
+ @visitormethod(Record)
+ def Record(self, node):
+ for opcode in node.opcodes:
+ print(opcode)
+ yield node
+
+
+class OperandsVisitor(Visitor):
+ @visitormethod(Record)
+ def Record(self, node):
+ if isinstance(node, Record):
+ for operand in node.dynamic_operands:
+ print(operand.name, ",".join(map(str, operand.span)))
+ for operand in node.static_operands:
+ if operand.name not in ("PO", "XO"):
+ desc = f"{operand.name}={operand.value}"
+ print(desc, ",".join(map(str, operand.span)))
+ yield node
+
+
+class PCodeVisitor(Visitor):
+ @visitormethod(Record)
+ def Record(self, node):
+ if isinstance(node, Record):
+ for line in node.pcode:
+ print(line)
+ yield node
+
+
+class ExtrasVisitor(Visitor):
+ @visitormethod(Record)
+ def Record(self, node):
+ for (name, extra) in node.extras.items():
+ print(name)
+ print(" sel", extra["sel"])
+ print(" reg", extra["reg"])
+ print(" seltype", extra["seltype"])
+ print(" idx", extra["idx"])
+ yield node
+
+