From: Dmitry Selyutin Date: Sat, 3 Jun 2023 09:59:09 +0000 (+0300) Subject: insndb/db: support opcodes command X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad730d7c6337a3c8918821dd1d4d6305ab0564f9;p=openpower-isa.git insndb/db: support opcodes command --- diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 96d881c5..753ab626 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -12,21 +12,45 @@ from openpower.insndb.types import ( def main(): - class ListVisitor(Visitor): + class GenericVisitor(Visitor): + def __init__(self, **_): + pass + + class ListVisitor(GenericVisitor): @contextlib.contextmanager def record(self, record): print(record.name) yield record + class OpcodesVisitor(GenericVisitor): + def __init__(self, insn, **_): + self.__insn = insn + return super().__init__() + + @contextlib.contextmanager + def record(self, record): + if record.name == self.__insn: + for opcode in record.opcodes: + print(opcode) + yield record + visitors = { "list": ListVisitor, + "opcodes": OpcodesVisitor, } parser = argparse.ArgumentParser() subparser = parser.add_subparsers(dest="command", required=True) - parser_list = subparser.add_parser("list") + parser_list = subparser.add_parser("list", + help="list all instructions") + parser_opcodes = subparser.add_parser("opcodes", + help="print instruction opcodes") + parser_opcodes.add_argument("insn", + metavar="INSN", + help="instruction") + args = vars(parser.parse_args()) command = args.pop("command") - visitor = visitors[command]() + visitor = visitors[command](**args) db = Database(find_wiki_dir()) db.visit(visitor=visitor)