insndb/db: support operands command
authorDmitry Selyutin <ghostmansd@gmail.com>
Sat, 3 Jun 2023 15:02:07 +0000 (18:02 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 22 Dec 2023 19:26:19 +0000 (19:26 +0000)
src/openpower/insndb/db.py

index d59595b447082792aa6ab188a4d6e87f569f092c..1ddb578e7ccb28a63c7e5ad0e83054e5f04330ce 100644 (file)
@@ -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)