insndb/db: update traversal algorithm mdis
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 23 Jun 2023 08:36:19 +0000 (11:36 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 23 Jun 2023 08:36:19 +0000 (11:36 +0300)
src/openpower/insndb/db.py

index 50fe9ebab5d767fab023cb4dc5c458a2fbaf0ddc..71e3a630098ab487b5a50453803b07b680f1e4cb 100644 (file)
@@ -182,14 +182,14 @@ class ExtrasVisitor(SVP64InstructionVisitor, SelectorsVisitor):
     @mdis.dispatcher.Hook(SVP64Record.ExtraMap)
     @contextlib.contextmanager
     def dispatch_extramap(self, node):
-        self.__index = -1
+        self.__index = 0
         yield node
 
     @mdis.dispatcher.Hook(SVP64Record.ExtraMap.Extra)
     @contextlib.contextmanager
     def dispatch_extramap_extra(self, node):
-        self.__index += 1
         yield node
+        self.__index += 1
 
     @mdis.dispatcher.Hook(SVP64Record.ExtraMap.Extra.Entry)
     @contextlib.contextmanager
@@ -272,12 +272,14 @@ def main():
     if not isinstance(visitor, InstructionVisitor):
         root = db
     else:
-        root = [db[args.pop("insn")]]
+        root = db[args.pop("insn")]
+
+    def traverse(root, visitor, walker):
+        with visitor(root):
+            for (node, *_) in walker(root):
+                traverse(root=node, visitor=visitor, walker=walker)
 
-    walker = Walker()
-    for (node, *_) in walker(root):
-        with visitor(node):
-            pass
+    traverse(root=root, visitor=visitor, walker=Walker())
 
 
 if __name__ == "__main__":