From: Dmitry Selyutin Date: Sat, 3 Jun 2023 17:02:24 +0000 (+0300) Subject: insndb/db: simplify commands structure X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=14cfea3a7097114b89f2a0d57d54b5386f3f3367;p=openpower-isa.git insndb/db: simplify commands structure --- diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index ce83c2f7..4f922c65 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -60,11 +60,23 @@ class PCodeVisitor(ConcreteInstructionVisitor): def main(): - visitors = { - "list": ListVisitor, - "opcodes": OpcodesVisitor, - "operands": OperandsVisitor, - "pcode": PCodeVisitor, + commands = { + "list": ( + ListVisitor, + "list available instructions", + ), + "opcodes": ( + OpcodesVisitor, + "print instruction opcodes", + ), + "operands": ( + OperandsVisitor, + "print instruction operands", + ), + "pcode": ( + PCodeVisitor, + "print instruction pseudocode", + ), } main_parser = argparse.ArgumentParser() @@ -73,23 +85,18 @@ def main(): action="store_true", default=False) main_subparser = main_parser.add_subparsers(dest="command", required=True) - main_subparser.add_parser("list", - help="list all instructions") - - for (command, help) in { - "opcodes": "print instruction opcodes", - "operands": "print instruction operands", - "pcode": "print instruction pseudocode", - }.items(): + + for (command, (visitor, help)) in commands.items(): parser = main_subparser.add_parser(command, help=help) - parser.add_argument("insn", metavar="INSN", help="instruction") + if issubclass(visitor, ConcreteInstructionVisitor): + parser.add_argument("insn", metavar="INSN", help="instruction") args = vars(main_parser.parse_args()) command = args.pop("command") log = args.pop("log") if not log: os.environ["SILENCELOG"] = "true" - visitor = visitors[command](**args) + visitor = commands[command][0](**args) db = Database(find_wiki_dir()) db.visit(visitor=visitor)