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
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]
# 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
# 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"
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)
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):