From 775bf84ef705daf01097e3df4f2081ceeebdf253 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 3 Apr 2020 22:10:29 +0100 Subject: [PATCH] create list of args, pass them in to function, return results too --- src/soc/decoder/pseudo/pywriter.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/soc/decoder/pseudo/pywriter.py b/src/soc/decoder/pseudo/pywriter.py index dade1fce..9cb8a220 100644 --- a/src/soc/decoder/pseudo/pywriter.py +++ b/src/soc/decoder/pseudo/pywriter.py @@ -9,6 +9,15 @@ def get_isasrc_dir(): fdir = os.path.split(fdir)[0] return os.path.join(fdir, "isa") +def create_args(reglist, extra=None): + args = set() + for reg in reglist: + args.add(reg) + args = list(args) + if extra: + args = [extra] + args + return ', '.join(args) + class PyISAWriter(ISA): def __init__(self): @@ -26,12 +35,20 @@ class PyISAWriter(ISA): pcode = '\n'.join(d.pcode) + '\n' print (pcode) pycode, regsused = convert_to_python(pcode) - f.write(" #%s\n" % repr(regsused)) - f.write(" def %s(self):\n" % page.replace(".", "_")) + # create list of arguments to call + regs = regsused['read_regs'] + regsused['uninit_regs'] + args = create_args(regs, 'self') + # create list of arguments to return + retargs = create_args(regsused['write_regs']) + f.write(" def %s(%s):\n" % (page.replace(".", "_"), args)) pycode = pycode.split("\n") pycode = '\n'.join(map(lambda x: " %s" % x, pycode)) - f.write("%s\n\n" % pycode) - + pycode = pycode.rstrip() + f.write(pycode + '\n') + if retargs: + f.write(" return (%s,)\n\n" % retargs) + else: + f.write("\n") if __name__ == '__main__': isa = PyISAWriter() -- 2.30.2