quite a big intrusive change in auto-assignment
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Aug 2021 15:03:07 +0000 (16:03 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 30 Aug 2021 15:03:07 +0000 (16:03 +0100)
variables that do not exist get auto-created based on the bit-width
at which they are first encountered

    prod[0:31]

creates a variable with

    prod = concat(0, repeat=32)

however this needs to be more complicated rather than just assume
it is a pair of constants

expressions can now be

     prod[0:XLEN-1]

which gets an ast.BinOp expression created on the RHS.

therefore allow the assignment "var = concat(...., repeat=xxxx)"
to accept computed expressions by returning an ast.BinOp(UPPER, "-", LOWER)
so that the resultant python code performs the subtract calculation

src/openpower/decoder/power_pseudo.py
src/openpower/decoder/pseudo/parser.py

index 4c5f36fd739c2478d1c41044f4d73e22e0eec730..a18d6a5feb1cf5bd5001555417f5bbccc88c8f0e 100644 (file)
@@ -215,7 +215,13 @@ assign_test2 = """
 prod[0:XLEN-1] <- 5
 """
 
-code = assign_test2
+assign_test = """
+prod[0:XLEN-1] <- MULS((RA)[XLEN/2:XLEN-1], (RB)[XLEN/2:XLEN-1])
+RT[XLEN/2:XLEN-1] <- prod[0:(XLEN/2)-1]
+RT[0:(XLEN/2)-1] <- undefined(prod[0:(XLEN/2)-1])
+"""
+
+code = assign_test
 #code = concat_test3
 #code = concat_test1
 #code = XLEN_test
index c93b74cd88cacbb21d38d18c070d20ea2a788dcc..94090281d3dd5de16f625c58cd3fa2ea3a66307d 100644 (file)
@@ -28,7 +28,7 @@ fregs = ['FRA', 'FRS', 'FRB', 'FRC', 'FRT', 'FRS']
 
 def Assign(autoassign, assignname, left, right, iea_mode):
     names = []
-    print("Assign", assignname, left, right)
+    print("Assign", autoassign, assignname, left, right)
     if isinstance(left, ast.Name):
         # Single assignment on left
         # XXX when doing IntClass, which will have an "eq" function,
@@ -62,10 +62,12 @@ def Assign(autoassign, assignname, left, right, iea_mode):
             # the declaration makes the slice-assignment "work"
             lower, upper, step = ls.lower, ls.upper, ls.step
             print("lower, upper, step", repr(lower), repr(upper), step)
-            if not isinstance(lower, ast.Constant) or \
-               not isinstance(upper, ast.Constant):
-                return res
-            qty = ast.Num(upper.value-lower.value)
+            # XXX relax constraint that indices on auto-assign have
+            # to be constants x[0:32]
+            #if not isinstance(lower, ast.Constant) or \
+            #   not isinstance(upper, ast.Constant):
+            #    return res
+            qty = ast.BinOp(upper, binary_ops['-'], lower)
             keywords = [ast.keyword(arg='repeat', value=qty)]
             l = [ast.Num(0)]
             right = ast.Call(ast.Name("concat", ast.Load()), l, keywords)
@@ -438,8 +440,14 @@ class PowerParser:
             if isinstance(p[1], ast.Name):
                 name = p[1].id
             elif isinstance(p[1], ast.Subscript):
+                print ("assign subscript", p[1].value,
+                                           self.declared_vars,
+                                           self.fnparm_vars,
+                                           self.special_regs)
+                print(astor.dump_tree(p[1]))
                 if isinstance(p[1].value, ast.Name):
                     name = p[1].value.id
+                    print ("assign subscript value to name", name)
                     if name in self.gprs:
                         # add to list of uninitialised
                         self.uninit_regs.add(name)