for insn in db:
try:
tree = parser.parse(code="\n".join(insn.pcode))
- for (level, line) in pc_code.code(name=insn.name, root=tree):
+ for (level, line) in pc_code.code(insn=insn, root=tree):
print(f"{' ' * 4 * level}{line}")
except Exception as exc:
print(insn.name)
print(insn.pcode)
raise exc
-code = """
-src <- [0]*64
-src[64-XLEN:63] <- (RS)
-result <- [0]*64
-do i = 0 to 1
- n <- i * 32
- result[n+0:n+7] <- 0
- result[n+8:n+19] <- DPD_TO_BCD(src[n+12:n+21])
- result[n+20:n+31] <- DPD_TO_BCD(src[n+22:n+31])
-RA <- result[64-XLEN:63]
-RA <- (C ? A : B)
-if a < b then RT <- (RA)
-else RT <- (RB)
-"""
+insn = db["tdi"]
+code = "\n".join(insn.pcode)
tree = parser.parse(code=code)
print(tree)
for (level, line) in pc_pseudocode.pseudocode(tree):
print(f"{' ' * 4 * level}{line}")
-for (level, line) in pc_code.code(name="cdtbcd", root=tree):
+for (level, line) in pc_code.code(insn=insn, root=tree):
print(f"{' ' * 4 * level}{line}")
class CodeVisitor(pc_util.Visitor):
- def __init__(self, name, root):
+ def __init__(self, insn, root):
self.__root = root
+ self.__insn = insn
self.__attrs = {}
self.__header = object()
self.__footer = object()
super().__init__(root=root)
self.__code[self.__header].emit(stmt="void")
- self.__code[self.__header].emit(stmt=f"oppc_{name}(void) {{")
+ self.__code[self.__header].emit(stmt=f"oppc_{insn.name}(void) {{")
with self.__code[self.__header]:
for decl in self.__decls:
self.__code[self.__header].emit(stmt=f"struct oppc_value {decl};")
raise NotImplementedError(type(node))
-def code(name, root):
- yield from CodeVisitor(name=name, root=root)
+def code(insn, root):
+ yield from CodeVisitor(insn=insn, root=root)