From: Dmitry Selyutin Date: Fri, 9 Jun 2023 18:27:57 +0000 (+0300) Subject: insndb/core: introduce Records type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=529d84ae63ecb05587933537e0c5bd0c47c8d04b;p=openpower-isa.git insndb/core: introduce Records type --- diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 5472502f..26e3c1a9 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -3720,6 +3720,19 @@ class SVP64Database: return None +class Records(tuple): + def __new__(cls, records): + return super().__new__(cls, sorted(records)) + + def subnodes(self, match=None): + if match is None: + match = lambda subnode: True + + for record in self: + if match(record): + yield record + + class Database(Node): def __init__(self, root): root = _pathlib.Path(root) @@ -3748,7 +3761,7 @@ class Database(Node): names[record.name] = record opcodes[section][record.PO].add(record) - self.__db = sorted(db) + self.__db = Records(db) self.__names = dict(sorted(names.items())) self.__opcodes = dict(sorted(opcodes.items())) @@ -3758,7 +3771,8 @@ class Database(Node): if match is None: match = lambda subnode: True - yield from filter(match, self) + if match(self.__db): + yield self.__db def __repr__(self): return repr(self.__db) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 2fce21b1..33586152 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -10,6 +10,7 @@ from openpower.insndb.core import ( Database, Extra, Record, + Records, Visitor, visit, ) @@ -138,6 +139,7 @@ def main(): visitor = commands[command][0]() db = Database(find_wiki_dir()) + records = next(db.subnodes(match=lambda node: isinstance(node, Records))) if command in ("list",): match = None else: @@ -145,7 +147,7 @@ def main(): def match(record): return (isinstance(record, Record) and (record.name == insn)) - for node in db.subnodes(match=match): + for node in records.subnodes(match=match): visit(visitor=visitor, node=node)