self.emitter.append("pass")
def on_Assign(self, stmt):
- return self.lhs(stmt.lhs)(self.rhs(stmt.rhs))
+ gen_rhs = f"({(1 << len(stmt.rhs)) - 1} & {self.rhs(stmt.rhs)})"
+ if stmt.rhs.shape().signed:
+ gen_rhs = f"sign({gen_rhs}, {-1 << (len(stmt.rhs) - 1)})"
+ return self.lhs(stmt.lhs)(gen_rhs)
def on_Switch(self, stmt):
gen_test = self.emitter.def_var("test",
self.assertStatement(stmt, [C(0b01, unsigned(2)), C(0b0001, signed(4))], C(1))
self.assertStatement(stmt, [C(0b11, unsigned(2)), C(0b1111, signed(4))], C(1))
+ def test_as_signed_issue_502(self):
+ stmt = lambda y, a: y.eq(a.as_signed())
+ self.assertStatement(stmt, [C(0b01, unsigned(2))], C(0b0001, signed(4)))
+ self.assertStatement(stmt, [C(0b11, unsigned(2))], C(0b1111, signed(4)))
+
def test_any(self):
stmt = lambda y, a: y.eq(a.any())
self.assertStatement(stmt, [C(0b00, 2)], C(0))