From 9eeb38e908c3ceb288b41110f222f5768ede8672 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 23 Jun 2023 11:36:19 +0300 Subject: [PATCH] insndb/db: update traversal algorithm --- src/openpower/insndb/db.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 50fe9eba..71e3a630 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -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__": -- 2.30.2