insndb/db: support tree command sketch
authorDmitry Selyutin <ghostmansd@gmail.com>
Sat, 10 Jun 2023 18:35:50 +0000 (21:35 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sat, 10 Jun 2023 18:35:50 +0000 (21:35 +0300)
src/openpower/insndb/db.py

index 6cd5d1c0564fdf6b1a3eeb2ae3d17c983fd3a135..fb9ee05cf45238a38a10d2e24cc56213800c496a 100644 (file)
@@ -39,6 +39,20 @@ class SVP64Instruction(Instruction):
         return self
 
 
+class TreeVisitor(Visitor):
+    def __init__(self):
+        self.__depth = 0
+        return super().__init__()
+
+    @contextlib.contextmanager
+    def __call__(self, node):
+        with super().__call__(node) as node:
+            print((" " * (self.__depth * 4)), repr(node))
+            self.__depth += 1
+            yield node
+            self.__depth -= 1
+
+
 class ListVisitor(Visitor):
     @visitormethod(Record)
     def Record(self, node):
@@ -98,6 +112,10 @@ class ExtrasVisitor(SVP64InstructionVisitor):
 
 def main():
     commands = {
+        "tree": (
+            TreeVisitor,
+            "list all records",
+        ),
         "list": (
             ListVisitor,
             "list available instructions",