From 96a20a642e1667ea9d40d6e378a7b5283304d84f Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 14 Jan 2024 21:56:05 +0300 Subject: [PATCH] oppc: pass insndb record --- src/openpower/oppc/__main__.py | 20 ++++---------------- src/openpower/oppc/pc_code.py | 9 +++++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index d8bcec71..ecf6aa0b 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -19,31 +19,19 @@ db = Database(find_wiki_dir()) 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}") diff --git a/src/openpower/oppc/pc_code.py b/src/openpower/oppc/pc_code.py index 6ac371cb..cfc3ddfc 100644 --- a/src/openpower/oppc/pc_code.py +++ b/src/openpower/oppc/pc_code.py @@ -24,8 +24,9 @@ class Call(pc_ast.Dataclass): 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() @@ -38,7 +39,7 @@ class CodeVisitor(pc_util.Visitor): 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};") @@ -594,5 +595,5 @@ class CodeVisitor(pc_util.Visitor): 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) -- 2.30.2