748f60abb139f108f59110e9dc2f05868751ac74
6 from openpower
.decoder
.power_enums
import (
9 from openpower
.insndb
.core
import (
15 class Instruction(str):
16 def __new__(cls
, string
):
18 if string
.startswith("sv."):
19 string
= string
[len("sv."):]
21 self
= super().__new
__(cls
, string
)
30 class SVP64Instruction(Instruction
):
31 def __new__(cls
, string
):
32 self
= super().__new
__(cls
, string
)
34 raise ValueError("illegal SVP64 instruction")
38 class RecordNameVisitor(Visitor
):
39 def __init__(self
, name
):
41 self
.__records
= set()
42 return super().__init
__()
44 @contextlib.contextmanager
45 def Record(self
, node
):
46 if node
.name
== self
.__name
:
47 self
.__records
.add(node
)
51 yield from self
.__records
54 class ListVisitor(Visitor
):
55 @contextlib.contextmanager
56 def Record(self
, node
):
61 class OpcodesVisitor(Visitor
):
62 @contextlib.contextmanager
63 def Record(self
, node
):
64 for opcode
in node
.opcodes
:
69 class OperandsVisitor(Visitor
):
70 @contextlib.contextmanager
71 def Record(self
, node
):
72 for operand
in node
.dynamic_operands
:
73 print(operand
.name
, ",".join(map(str, operand
.span
)))
74 for operand
in node
.static_operands
:
75 if operand
.name
not in ("PO", "XO"):
76 desc
= f
"{operand.name}={operand.value}"
77 print(desc
, ",".join(map(str, operand
.span
)))
81 class PCodeVisitor(Visitor
):
82 @contextlib.contextmanager
83 def Record(self
, node
):
84 for line
in node
.pcode
:
89 class ExtrasVisitor(Visitor
):
90 @contextlib.contextmanager
91 def Extra(self
, node
):
93 print(" sel", node
.sel
)
94 print(" reg", node
.reg
)
95 print(" seltype", node
.seltype
)
96 print(" idx", node
.idx
)
104 "list available instructions",
108 "print instruction opcodes",
112 "print instruction operands",
116 "print instruction pseudocode",
120 "print instruction extras (SVP64)",
124 main_parser
= argparse
.ArgumentParser()
125 main_parser
.add_argument("-l", "--log",
126 help="activate logging",
129 main_subparser
= main_parser
.add_subparsers(dest
="command", required
=True)
131 for (command
, (visitor
, helper
)) in commands
.items():
132 parser
= main_subparser
.add_parser(command
, help=helper
)
133 if command
not in ("list",):
134 if command
in ("extras",):
135 arg_cls
= SVP64Instruction
137 arg_cls
= Instruction
138 parser
.add_argument("insn", type=arg_cls
,
139 metavar
="INSN", help="instruction")
141 args
= vars(main_parser
.parse_args())
142 command
= args
.pop("command")
143 log
= args
.pop("log")
145 os
.environ
["SILENCELOG"] = "true"
146 visitor
= commands
[command
][0]()
148 db
= Database(find_wiki_dir())
149 if command
in ("list",):
152 match
= RecordNameVisitor(name
=args
["insn"])
154 nodes
= frozenset(match
)
157 with
visitor(node
=node
):
161 if __name__
== "__main__":