5 from openpower
.decoder
.power_enums
import (
8 from openpower
.insndb
.core
import (
14 class BaseVisitor(Visitor
):
15 def __init__(self
, **_
):
19 class ListVisitor(BaseVisitor
):
20 @contextlib.contextmanager
21 def record(self
, record
):
26 class ConcreteInstructionVisitor(BaseVisitor
):
27 def __init__(self
, insn
, **_
):
29 return super().__init
__()
31 def handler(self
, record
):
32 raise NotImplementedError
34 @contextlib.contextmanager
35 def record(self
, record
):
36 if record
.name
== self
.__insn
:
37 self
.handler(record
=record
)
41 class OpcodesVisitor(ConcreteInstructionVisitor
):
42 def handler(self
, record
):
43 for opcode
in record
.opcodes
:
47 class OperandsVisitor(ConcreteInstructionVisitor
):
48 def handler(self
, record
):
49 for operand
in record
.dynamic_operands
:
51 for operand
in record
.static_operands
:
52 if operand
.name
not in ("PO", "XO"):
53 print(operand
.name
, operand
.value
, sep
="=")
59 "opcodes": OpcodesVisitor
,
60 "operands": OperandsVisitor
,
62 main_parser
= argparse
.ArgumentParser()
63 main_subparser
= main_parser
.add_subparsers(dest
="command", required
=True)
64 main_subparser
.add_parser("list",
65 help="list all instructions")
67 for (command
, help) in {
68 "opcodes": "print instruction opcodes",
69 "operands": "print instruction operands",
71 parser
= main_subparser
.add_parser(command
, help=help)
72 parser
.add_argument("insn", metavar
="INSN", help="instruction")
74 args
= vars(main_parser
.parse_args())
75 command
= args
.pop("command")
76 visitor
= visitors
[command
](**args
)
78 db
= Database(find_wiki_dir())
79 db
.visit(visitor
=visitor
)