temporary hack-revert, the original is now in branch "paths"
[openpower-isa.git] / src / openpower / insndb / db.py
index 15b915b99bf2fa69138bc5607de1bd57e09b9570..fa5eb267ea7ae14f442183b260c2580b16d56a80 100644 (file)
@@ -8,8 +8,11 @@ from openpower.decoder.power_enums import (
 )
 from openpower.insndb.core import (
     Database,
+    Dataclass,
+    Dict,
     Record,
     Records,
+    Tuple,
     Visitor,
     visit,
     visitormethod,
@@ -42,14 +45,19 @@ class SVP64Instruction(Instruction):
 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):
-            print((" " * (self.__depth * 4)), path)
+            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
 
 
@@ -163,9 +171,9 @@ def main():
     visitor = commands[command][0]()
 
     db = Database(find_wiki_dir())
-    (path, 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):