)
from openpower.insndb.core import (
Database,
+ Dataclass,
+ Dict,
Record,
Records,
+ Tuple,
Visitor,
visit,
visitormethod,
return self
+class TreeVisitor(Visitor):
+ def __init__(self):
+ self.__depth = 0
+ self.__path = [""]
+ return super().__init__()
+
+ @contextlib.contextmanager
+ def __call__(self, path, node):
+ with super().__call__(path=path, node=node):
+ self.__path.append(path)
+ print("/".join(self.__path))
+ if not isinstance(node, (Dataclass, Tuple, Dict)):
+ print(" ", repr(node), sep="")
+ self.__depth += 1
+ yield node
+ self.__path.pop(-1)
+ self.__depth -= 1
+
+
class ListVisitor(Visitor):
@visitormethod(Record)
- def Record(self, node):
+ def Record(self, path, node):
print(node.name)
yield node
class OpcodesVisitor(InstructionVisitor):
@visitormethod(Record)
- def Record(self, node):
+ def Record(self, path, node):
for opcode in node.opcodes:
print(opcode)
yield node
class OperandsVisitor(InstructionVisitor):
@visitormethod(Record)
- def Record(self, node):
+ def Record(self, path, node):
if isinstance(node, Record):
for operand in node.dynamic_operands:
print(operand.name, ",".join(map(str, operand.span)))
class PCodeVisitor(InstructionVisitor):
@visitormethod(Record)
- def Record(self, node):
+ def Record(self, path, node):
if isinstance(node, Record):
for line in node.pcode:
print(line)
class ExtrasVisitor(SVP64InstructionVisitor):
@visitormethod(Record)
- def Record(self, node):
+ def Record(self, path, node):
for (name, extra) in node.extras.items():
print(name)
print(" sel", extra["sel"])
def main():
commands = {
+ "tree": (
+ TreeVisitor,
+ "list all records",
+ ),
"list": (
ListVisitor,
"list available instructions",
visitor = commands[command][0]()
db = Database(find_wiki_dir())
- records = next(db.walk(match=lambda node: isinstance(node, Records)))
+ (path, records) = next(db.walk(match=lambda pair: isinstance(pair, Records)))
if not isinstance(visitor, InstructionVisitor):
- match = None
+ match = lambda _: True
else:
insn = args.pop("insn")
def match(record):
return (isinstance(record, Record) and (record.name == insn))
- for node in records.walk(match=match):
- visit(visitor=visitor, node=node)
+ for (subpath, node) in records.walk(match=match):
+ visit(visitor=visitor, node=node, path=subpath)
if __name__ == "__main__":