use set not list to make regs unique
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 13:39:28 +0000 (14:39 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 13:39:28 +0000 (14:39 +0100)
src/soc/decoder/pseudo/parser.py
src/soc/decoder/pseudo/pywriter.py

index 6c67265b9c51478bd7aaae7ceb17ffea32612e82..8b38c8023e3f3ca0c56f50d75ae691cff3c4ae78 100644 (file)
@@ -197,9 +197,9 @@ class PowerParser:
         self.gprs = {}
         for rname in ['RA', 'RB', 'RC', 'RT', 'RS']:
             self.gprs[rname] = None
-        self.read_regs = []
-        self.uninit_regs = []
-        self.write_regs = []
+        self.read_regs = set()
+        self.uninit_regs = set()
+        self.write_regs = set()
 
     # The grammar comments come from Python's Grammar/Grammar file
 
@@ -310,10 +310,10 @@ class PowerParser:
                 name = p[1].value.id
                 if name in self.gprs:
                     # add to list of uninitialised
-                    self.uninit_regs.append(name)
+                    self.uninit_regs.add(name)
             print("expr assign", name, p[1])
             if name in self.gprs:
-                self.write_regs.append(name)  # add to list of regs to write
+                self.write_regs.add(name)  # add to list of regs to write
             p[0] = Assign(p[1], p[3])
 
     def p_flow_stmt(self, p):
@@ -488,7 +488,7 @@ class PowerParser:
         if isinstance(p[2], ast.Name):
             print("tuple name", p[2].id)
             if p[2].id in self.gprs:
-                self.read_regs.append(p[2].id)  # add to list of regs to read
+                self.read_regs.add(p[2].id)  # add to list of regs to read
                 #p[0] = ast.Subscript(ast.Name("GPR"), ast.Str(p[2].id))
                 # return
         p[0] = p[2]
index 238ef6464887f8526e1ba9b38c18bbf76b997d61..6198dcd3030875c333c3898ff65ea9246c4cd1e7 100644 (file)
@@ -49,7 +49,7 @@ class PyISAWriter(ISA):
                 print (pcode)
                 pycode, rused = convert_to_python(pcode)
                 # create list of arguments to call
-                regs = rused['read_regs'] + rused['uninit_regs']
+                regs = list(rused['read_regs']) + list(rused['uninit_regs'])
                 args = create_args(regs, 'self')
                 # create list of arguments to return
                 retargs = create_args(rused['write_regs'])