return ast.Compare(left, [ast.Eq()], [right])
binary_ops = {
+ "&": ast.BitAnd(),
+ "|": ast.BitOr(),
"+": ast.Add(),
"-": ast.Sub(),
"*": ast.Mult(),
class PowerParser:
precedence = (
+ ("left", "BITOR", "BITAND"),
("left", "EQ", "GT", "LT", "LE", "GE", "LTU", "GTU"),
("left", "PLUS", "MINUS"),
("left", "MULT", "DIV"),
| comparison GTU comparison
| comparison LT comparison
| comparison GT comparison
+ | comparison BITOR comparison
+ | comparison BITAND comparison
| PLUS comparison
| MINUS comparison
| comparison APPEND comparison
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
- return other <= self.value
+ return onebit(other <= self.value)
assert False
def __gt__(self, other):
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
- return other > self.value
+ return onebit(other > self.value)
assert False
def __lt__(self, other):
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
- return other < self.value
+ return onebit(other < self.value)
assert False
def __eq__(self, other):
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
- return other == self.value
+ return onebit(other == self.value)
assert False
def __repr__(self):
return "SelectableInt(value={:x}, bits={})".format(self.value,
self.bits)
+def onebit(bit):
+ return SelectableInt(1 if bit else 0, 1)
+
def selectltu(lhs, rhs):
""" less-than (unsigned)
"""
if isinstance(rhs, SelectableInt):
rhs = rhs.value
- return lhs.value < rhs
+ return onebit(lhs.value < rhs)
def selectgtu(lhs, rhs):
""" greater-than (unsigned)
"""
if isinstance(rhs, SelectableInt):
rhs = rhs.value
- return lhs.value > rhs
+ return onebit(lhs.value > rhs)
# XXX this probably isn't needed...