From f63b1c7d45ffafb8c7af6740ec6fb9586080686e Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 16 Jan 2024 22:09:45 +0300 Subject: [PATCH] oppc: refactor output --- src/openpower/oppc/__main__.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index e3a12f96..846f3ab8 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -13,6 +13,7 @@ import openpower.oppc.pc_parser as pc_parser import openpower.oppc.pc_pseudocode as pc_pseudocode +table = {} lexer = pc_lexer.IndentLexer(debug=False) parser = pc_parser.Parser(lexer=lexer) db = Database(find_wiki_dir()) @@ -21,19 +22,18 @@ for insn in db: continue try: tree = parser.parse(code="\n".join(insn.pcode)) - for (level, line) in pc_code.code(insn=insn, root=tree): - print(f"{' ' * 4 * level}{line}") + code = pc_code.code(insn=insn, root=tree) + handler = ("oppc_handler_" + insn.name.replace(".", "_")) + table[handler] = code except Exception as exc: print(insn.name) print(insn.pcode) raise exc -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(insn=insn, root=tree): - print(f"{' ' * 4 * level}{line}") +for (handler, code) in table.items(): + print("void") + print(f"{handler}(struct oppc_value const *insn) {{") + for (level, line) in code: + print(f"{' ' * 4 * (level + 1)}{line}") + print(f"}}") + print() -- 2.30.2