From 32957c710685353a698799b1784d14b342193e32 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 4 Apr 2020 17:15:39 +0100 Subject: [PATCH] sigh change syntax to (RA|0) --- src/soc/decoder/power_pseudo.py | 41 ++++++++++++++++++++------------ src/soc/decoder/pseudo/parser.py | 23 +++++++++++++++++- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py index d66d3f2b..c837ce86 100644 --- a/src/soc/decoder/power_pseudo.py +++ b/src/soc/decoder/power_pseudo.py @@ -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) diff --git a/src/soc/decoder/pseudo/parser.py b/src/soc/decoder/pseudo/parser.py index d72fc297..9cd669a0 100644 --- a/src/soc/decoder/pseudo/parser.py +++ b/src/soc/decoder/pseudo/parser.py @@ -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): -- 2.30.2