create list of args, pass them in to function, return results too
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 21:10:29 +0000 (22:10 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 3 Apr 2020 21:10:34 +0000 (22:10 +0100)
src/soc/decoder/pseudo/pywriter.py

index dade1fceff2b47031b9adc3c63404e40cdd6d245..9cb8a220f1dd058d6c94e700508b7811827b8a83 100644 (file)
@@ -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()