From: Dmitry Selyutin Date: Sat, 3 Jun 2023 15:02:07 +0000 (+0300) Subject: insndb/db: support operands command X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f524fab0b377cfc26b648715eb07e3b547c2f995;p=openpower-isa.git insndb/db: support operands command --- diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index d59595b4..1ddb578e 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -44,22 +44,34 @@ class OpcodesVisitor(ConcreteInstructionVisitor): print(opcode) +class OperandsVisitor(ConcreteInstructionVisitor): + def handler(self, record): + for operand in record.dynamic_operands: + print(operand.name) + for operand in record.static_operands: + if operand.name not in ("PO", "XO"): + print(operand.name, operand.value, sep="=") + + def main(): visitors = { "list": ListVisitor, "opcodes": OpcodesVisitor, + "operands": OperandsVisitor, } - parser = argparse.ArgumentParser() - subparser = parser.add_subparsers(dest="command", required=True) - parser_list = subparser.add_parser("list", + main_parser = argparse.ArgumentParser() + main_subparser = main_parser.add_subparsers(dest="command", required=True) + main_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()) + for (command, help) in { + "opcodes": "print instruction opcodes", + "operands": "print instruction operands", + }.items(): + parser = main_subparser.add_parser(command, help=help) + parser.add_argument("insn", metavar="INSN", help="instruction") + + args = vars(main_parser.parse_args()) command = args.pop("command") visitor = visitors[command](**args)