hdl,back,sim: accept .as_signed() and .as_unsigned() on LHS.

These operators are ignored when they are encountered on LHS, as
the signedness of the assignment target does not matter in Amaranth.
.as_signed() appears on LHS of assigns to signed aggregate fields.
This commit is contained in:
Catherine 2022-04-06 04:15:48 +00:00
parent 90fcbfc357
commit da26f1c915
4 changed files with 20 additions and 0 deletions

View file

@ -62,6 +62,10 @@ class SimulatorUnitTestCase(FHDLTestCase):
self.assertStatement(stmt, [C(0b01, signed(2)), C(0b0001, unsigned(4))], C(1))
self.assertStatement(stmt, [C(0b11, signed(2)), C(0b0011, unsigned(4))], C(1))
def test_as_unsigned_lhs(self):
stmt = lambda y, a: y.as_unsigned().eq(a)
self.assertStatement(stmt, [C(0b01, unsigned(2))], C(0b0001, signed(4)))
def test_as_signed(self):
stmt = lambda y, a, b: y.eq(a.as_signed() == b)
self.assertStatement(stmt, [C(0b01, unsigned(2)), C(0b0001, signed(4))], C(1))
@ -72,6 +76,10 @@ class SimulatorUnitTestCase(FHDLTestCase):
self.assertStatement(stmt, [C(0b01, unsigned(2))], C(0b0001, signed(4)))
self.assertStatement(stmt, [C(0b11, unsigned(2))], C(0b1111, signed(4)))
def test_as_signed_lhs(self):
stmt = lambda y, a: y.as_signed().eq(a)
self.assertStatement(stmt, [C(0b01, unsigned(2))], C(0b0001, signed(4)))
def test_any(self):
stmt = lambda y, a: y.eq(a.any())
self.assertStatement(stmt, [C(0b00, 2)], C(0))