return ast.Assign([ast.AssTuple(ass_list)], right)
elif isinstance(left, ast.Subscript):
return ast.Assign([left], right)
+ # XXX HMMM probably not needed...
+ ls = left.slice
+ if isinstance(ls, ast.Slice):
+ lower, upper, step = ls.lower, ls.upper, ls.step
+ print ("slice assign", lower, upper, step)
+ if step is None:
+ ls = (lower, upper, None)
+ else:
+ ls = (lower, upper, step)
+ ls = ast.Tuple(ls)
+ return ast.Call(ast.Name("selectassign"),
+ [left.value, ls, right], [])
else:
print ("Assign fail")
raise SyntaxError("Can't do that yet")
# factor: ('+'|'-'|'~') factor | power
# comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
+def make_le_compare(arg):
+ (left, right) = arg
+ return ast.Compare(left, [ast.Le()], [right])
+def make_ge_compare(arg):
+ (left, right) = arg
+ return ast.Compare(left, [ast.Ge()], [right])
def make_lt_compare(arg):
(left, right) = arg
return ast.Compare(left, [ast.Lt()], [right])
"-": ast.Sub(),
"*": ast.Mult(),
"/": ast.Div(),
+ "<=": make_le_compare,
+ ">=": make_ge_compare,
"<": make_lt_compare,
">": make_gt_compare,
"=": make_eq_compare,
class PowerParser:
precedence = (
- ("left", "EQ", "GT", "LT"),
+ ("left", "EQ", "GT", "LT", "LE", "GE", "LTU", "GTU"),
("left", "PLUS", "MINUS"),
("left", "MULT", "DIV"),
)
for rname in ['RA', 'RB', 'RC', 'RT', 'RS']:
self.gprs[rname] = None
self.read_regs = []
+ self.uninit_regs = []
self.write_regs = []
# The grammar comments come from Python's Grammar/Grammar file
name = p[1].id
elif isinstance(p[1], ast.Subscript):
name = p[1].value.id
+ if name in self.gprs:
+ self.uninit_regs.append(name) # add to list of uninitialised
print ("expr assign", name, p[1])
if name in self.gprs:
self.write_regs.append(name) # add to list of regs to write
| comparison MINUS comparison
| comparison MULT comparison
| comparison DIV comparison
- | comparison LT comparison
| comparison EQ comparison
+ | comparison LE comparison
+ | comparison GE comparison
+ | comparison LTU comparison
+ | comparison GTU comparison
+ | comparison LT comparison
| comparison GT comparison
| PLUS comparison
| MINUS comparison
| power"""
if len(p) == 4:
print (list(p))
- if p[2] == '||':
+ if p[2] == '<u':
+ p[0] = ast.Call(ast.Name("ltu"), (p[1], p[3]), [])
+ elif p[2] == '>u':
+ p[0] = ast.Call(ast.Name("gtu"), (p[1], p[3]), [])
+ elif p[2] == '||':
l = check_concat(p[1]) + check_concat(p[3])
p[0] = ast.Call(ast.Name("concat"), l, [])
elif p[2] in ['<', '>', '=']:
value = value << start
self.value = (self.value & ~mask) | (value & mask)
+ def __ge__(self, other):
+ if isinstance(other, SelectableInt):
+ assert other.bits == self.bits
+ other = other.value
+ if isinstance(other, int):
+ return other >= self.value
+ assert False
+
+ def __le__(self, other):
+ if isinstance(other, SelectableInt):
+ assert other.bits == self.bits
+ other = other.value
+ if isinstance(other, int):
+ return other <= self.value
+ assert False
+
+ def __gt__(self, other):
+ if isinstance(other, SelectableInt):
+ assert other.bits == self.bits
+ other = other.value
+ if isinstance(other, int):
+ return other > self.value
+ assert False
+
+ def __lt__(self, other):
+ if isinstance(other, SelectableInt):
+ assert other.bits == self.bits
+ other = other.value
+ if isinstance(other, int):
+ return other < self.value
+ assert False
+
def __eq__(self, other):
if isinstance(other, SelectableInt):
- return other.value == self.value and other.bits == self.bits
+ assert other.bits == self.bits
+ other = other.value
if isinstance(other, int):
return other == self.value
assert False
return "SelectableInt(value={:x}, bits={})".format(self.value,
self.bits)
+def selectltu(lhs, rhs):
+ """ less-than (unsigned)
+ """
+ if isinstance(rhs, SelectableInt):
+ rhs = rhs.value
+ return lhs.value < rhs
+
+def selectgtu(lhs, rhs):
+ """ greater-than (unsigned)
+ """
+ if isinstance(rhs, SelectableInt):
+ rhs = rhs.value
+ return lhs.value > rhs
+
+
# XXX this probably isn't needed...
def selectassign(lhs, idx, rhs):
if isinstance(idx, tuple):
self.assertEqual(d.value, a.value | b.value)
self.assertEqual(e.value, a.value ^ b.value)
self.assertEqual(f.value, 0xF0)
-
def test_get(self):
a = SelectableInt(0xa2, 8)