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
="=")
56 class PCodeVisitor(ConcreteInstructionVisitor
):
57 def handler(self
, record
):
58 for line
in record
.pcode
:
65 "opcodes": OpcodesVisitor
,
66 "operands": OperandsVisitor
,
67 "pcode": PCodeVisitor
,
70 main_parser
= argparse
.ArgumentParser()
71 main_parser
.add_argument("-l", "--log",
72 help="activate logging",
75 main_subparser
= main_parser
.add_subparsers(dest
="command", required
=True)
76 main_subparser
.add_parser("list",
77 help="list all instructions")
79 for (command
, help) in {
80 "opcodes": "print instruction opcodes",
81 "operands": "print instruction operands",
82 "pcode": "print instruction pseudocode",
84 parser
= main_subparser
.add_parser(command
, help=help)
85 parser
.add_argument("insn", metavar
="INSN", help="instruction")
87 args
= vars(main_parser
.parse_args())
88 command
= args
.pop("command")
91 os
.environ
["SILENCELOG"] = "true"
92 visitor
= visitors
[command
](**args
)
94 db
= Database(find_wiki_dir())
95 db
.visit(visitor
=visitor
)