From: Luke Kenneth Casson Leighton Date: Fri, 3 Apr 2020 21:10:29 +0000 (+0100) Subject: create list of args, pass them in to function, return results too X-Git-Tag: div_pipeline~1544 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=775bf84ef705daf01097e3df4f2081ceeebdf253;p=soc.git create list of args, pass them in to function, return results too --- 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()