From: Dmitry Selyutin Date: Sun, 3 Dec 2023 12:49:24 +0000 (+0300) Subject: power_pseudo: unify Python code generation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a2afa8d0f954259712c7cbb7c17b5ddbbbfb7dd4;p=openpower-isa.git power_pseudo: unify Python code generation --- diff --git a/src/openpower/decoder/power_pseudo.py b/src/openpower/decoder/power_pseudo.py index e9dcbd55..836b6f81 100644 --- a/src/openpower/decoder/power_pseudo.py +++ b/src/openpower/decoder/power_pseudo.py @@ -259,27 +259,34 @@ def get_reg_hex(reg): return hex(reg.value) -def convert_to_pure_python(pcode, helper=False, filename="string"): - - gsc = GardenSnakeCompiler(form=None, incl_carry=False, helper=helper) - +def compile(pcode, form, helper, incl_carry, filename): + fields = { + "read_regs", + "write_regs", + "uninit_regs", + "special_regs", + "op_fields", + } + gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry, helper=helper) tree = gsc.compile(pcode, mode="exec", filename=filename) tree = ast.fix_missing_locations(tree) - return astor.to_source(tree) + regs = {field:getattr(gsc.parser, field) for field in fields} + + return (tree, regs) def convert_to_python(pcode, form, incl_carry, helper=False, filename="string"): - log("form", form) - gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry, helper=helper) + (tree, regs) = compile(pcode=pcode, + form=form, helper=helper, + incl_carry=incl_carry, filename=filename) + return (astor.to_source(tree), regs) - tree = gsc.compile(pcode, mode="exec", filename=filename) - tree = ast.fix_missing_locations(tree) - regsused = {'read_regs': gsc.parser.read_regs, - 'write_regs': gsc.parser.write_regs, - 'uninit_regs': gsc.parser.uninit_regs, - 'special_regs': gsc.parser.special_regs, - 'op_fields': gsc.parser.op_fields} - return astor.to_source(tree), regsused + +def convert_to_pure_python(pcode, helper=False, filename="string"): + (tree, _) = compile(form=None, + pcode=pcode, helper=helper, + incl_carry=False, filename=filename) + return astor.to_source(tree) def check_in_gitignore(output_file):