sigh change syntax to (RA|0)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 16:15:39 +0000 (17:15 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 4 Apr 2020 16:15:39 +0000 (17:15 +0100)
src/soc/decoder/power_pseudo.py
src/soc/decoder/pseudo/parser.py

index d66d3f2b7fc99ef9337b207da20fe53dae8b71fb..c837ce8635bc85498ea02b496e7a5cfdd5d0d690 100644 (file)
@@ -101,7 +101,14 @@ x <- [0] * 16
 RT <- (RA) + EXTS(SI || [0]*16)
 """
 
-code = testmul
+testgetzero = """
+RS <- (RA|0)
+RS <- RS + 1
+print(RS)
+"""
+
+#code = testmul
+code = testgetzero
 #code = testreg
 #code = cnttzd
 #code = cmpi
@@ -126,24 +133,27 @@ class GPR(dict):
     def __init__(self, sd, regfile):
         dict.__init__(self)
         self.sd = sd
-        self.regfile = regfile
         for i in range(32):
-            self[i] = SelectableInt(0, 64)
+            self[i] = SelectableInt(regfile[i], 64)
 
     def set_form(self, form):
         self.form = form
 
-    def ___getitem__(self, attr):
-        print("GPR getitem", attr)
+    def getz(self, rnum):
+        #rnum = rnum.value # only SelectableInt allowed
+        print("GPR getzero", rnum)
+        if rnum == 0:
+            return SelectableInt(0, 64)
+        return self[rnum]
+
+    def _get_regnum(self, attr):
         getform = self.sd.sigforms[self.form]
         rnum = getattr(getform, attr)
-        print("GPR get", rnum, rnum, dir(rnum))
-        l = list(rnum)
-        print(l[0]._as_const())
-        # for x in rnum:
-        #print (x, x.value, dir(x))
-        #print (x.value, dir(x.value))
-        print(list(rnum))
+        return rnum
+
+    def ___getitem__(self, attr):
+        print("GPR getitem", attr)
+        rnum = self._get_regnum(attr)
         return self.regfile[rnum]
 
 
@@ -166,7 +176,7 @@ def test():
     # XXX unused!  see GPR instead
     gsc.regfile = {}
     for i in range(32):
-        gsc.regfile[i] = 0
+        gsc.regfile[i] = i
     gsc.gpr = GPR(gsc.parser.sd, gsc.regfile)
 
     _compile = gsc.compile
@@ -235,7 +245,8 @@ def test():
             # read regs, drop them into dict for function
             for rname in gsc.parser.read_regs:
                 regidx = yield getattr(decode.sigforms['X'], rname)
-                d[rname] = gsc.gpr[regidx]
+                d[rname] = gsc.gpr[regidx] # contents of regfile
+                d["_%s" % rname] = regidx # actual register value
                 print("read reg", rname, regidx, get_reg_hex(d[rname]))
 
             exec(compiled_code, d)  # code gets executed here in dict "d"
@@ -251,8 +262,8 @@ def test():
 
             for wname in gsc.parser.write_regs:
                 reg = getform[wname]
-                print("write regs", wname, d[wname], reg)
                 regidx = yield reg
+                print("write regs", regidx, wname, d[wname], reg)
                 gsc.gpr[regidx] = d[wname]
 
     sim.add_process(process)
index d72fc297aa7f6dac7e3eda4f68a212870f0135cf..9cd669a0dec6dc2fc0c3cdf04abb073098edc891 100644 (file)
@@ -486,13 +486,34 @@ class PowerParser:
     def p_atom_tuple(self, p):
         """atom : LPAR testlist RPAR"""
         print("tuple", p[2])
+        print("astor dump")
+        print(astor.dump_tree(p[2]))
+
         if isinstance(p[2], ast.Name):
             print("tuple name", p[2].id)
             if p[2].id in self.gprs:
                 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]
+            p[0] = p[2]
+        elif isinstance(p[2], ast.BinOp):
+            if isinstance(p[2].left, ast.Name) and \
+               isinstance(p[2].right, ast.Constant) and \
+                p[2].right.value == 0 and \
+                p[2].left.id in self.gprs:
+                    rid = p[2].left.id
+                    self.read_regs.add(rid)  # add to list of regs to read
+                    # create special call to GPR.getz
+                    gprz = ast.Name("GPR")
+                    gprz = ast.Attribute(gprz, "getz")   # get testzero function
+                    # *sigh* see class GPR.  we need index itself not reg value
+                    ridx = ast.Name("_%s" % rid)
+                    p[0] = ast.Call(gprz, [ridx], [])
+                    print("tree", astor.dump_tree(p[0]))
+            else:
+                p[0] = p[2]
+        else:
+            p[0] = p[2]
 
     # trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
     def p_trailer(self, p):