hdl.ast: deprecate Value.part, add Value.{bit,word}_select.
Fixes #148.
This commit is contained in:
parent
bcdc280a87
commit
94e13effad
6 changed files with 105 additions and 29 deletions
|
|
@ -294,24 +294,52 @@ class SliceTestCase(FHDLTestCase):
|
|||
self.assertEqual(repr(s1), "(slice (const 4'd10) 2:3)")
|
||||
|
||||
|
||||
class PartTestCase(FHDLTestCase):
|
||||
class BitSelectTestCase(FHDLTestCase):
|
||||
def setUp(self):
|
||||
self.c = Const(0, 8)
|
||||
self.s = Signal(max=self.c.nbits)
|
||||
|
||||
def test_shape(self):
|
||||
s1 = self.c.part(self.s, 2)
|
||||
s1 = self.c.bit_select(self.s, 2)
|
||||
self.assertEqual(s1.shape(), (2, False))
|
||||
s2 = self.c.part(self.s, 0)
|
||||
s2 = self.c.bit_select(self.s, 0)
|
||||
self.assertEqual(s2.shape(), (0, False))
|
||||
|
||||
def test_stride(self):
|
||||
s1 = self.c.bit_select(self.s, 2)
|
||||
self.assertEqual(s1.stride, 1)
|
||||
|
||||
def test_width_bad(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.c.part(self.s, -1)
|
||||
self.c.bit_select(self.s, -1)
|
||||
|
||||
def test_repr(self):
|
||||
s = self.c.part(self.s, 2)
|
||||
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2)")
|
||||
s = self.c.bit_select(self.s, 2)
|
||||
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 1)")
|
||||
|
||||
|
||||
class WordSelectTestCase(FHDLTestCase):
|
||||
def setUp(self):
|
||||
self.c = Const(0, 8)
|
||||
self.s = Signal(max=self.c.nbits)
|
||||
|
||||
def test_shape(self):
|
||||
s1 = self.c.word_select(self.s, 2)
|
||||
self.assertEqual(s1.shape(), (2, False))
|
||||
|
||||
def test_stride(self):
|
||||
s1 = self.c.word_select(self.s, 2)
|
||||
self.assertEqual(s1.stride, 2)
|
||||
|
||||
def test_width_bad(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.c.word_select(self.s, 0)
|
||||
with self.assertRaises(TypeError):
|
||||
self.c.word_select(self.s, -1)
|
||||
|
||||
def test_repr(self):
|
||||
s = self.c.word_select(self.s, 2)
|
||||
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 2)")
|
||||
|
||||
|
||||
class CatTestCase(FHDLTestCase):
|
||||
|
|
|
|||
|
|
@ -151,18 +151,30 @@ class SimulatorUnitTestCase(FHDLTestCase):
|
|||
stmt2 = lambda y, a: y[2:4].eq(a)
|
||||
self.assertStatement(stmt2, [C(0b01, 2)], C(0b11110111, 8), reset=0b11111011)
|
||||
|
||||
def test_part(self):
|
||||
stmt = lambda y, a, b: y.eq(a.part(b, 3))
|
||||
def test_bit_select(self):
|
||||
stmt = lambda y, a, b: y.eq(a.bit_select(b, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(0)], C(0b100, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(2)], C(0b101, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(3)], C(0b110, 3))
|
||||
|
||||
def test_part_lhs(self):
|
||||
stmt = lambda y, a, b: y.part(a, 3).eq(b)
|
||||
def test_bit_select_lhs(self):
|
||||
stmt = lambda y, a, b: y.bit_select(a, 3).eq(b)
|
||||
self.assertStatement(stmt, [C(0), C(0b100, 3)], C(0b11111100, 8), reset=0b11111111)
|
||||
self.assertStatement(stmt, [C(2), C(0b101, 3)], C(0b11110111, 8), reset=0b11111111)
|
||||
self.assertStatement(stmt, [C(3), C(0b110, 3)], C(0b11110111, 8), reset=0b11111111)
|
||||
|
||||
def test_word_select(self):
|
||||
stmt = lambda y, a, b: y.eq(a.word_select(b, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(0)], C(0b100, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(1)], C(0b110, 3))
|
||||
self.assertStatement(stmt, [C(0b10110100, 8), C(2)], C(0b010, 3))
|
||||
|
||||
def test_word_select_lhs(self):
|
||||
stmt = lambda y, a, b: y.word_select(a, 3).eq(b)
|
||||
self.assertStatement(stmt, [C(0), C(0b100, 3)], C(0b11111100, 8), reset=0b11111111)
|
||||
self.assertStatement(stmt, [C(1), C(0b101, 3)], C(0b11101111, 8), reset=0b11111111)
|
||||
self.assertStatement(stmt, [C(2), C(0b110, 3)], C(0b10111111, 8), reset=0b11111111)
|
||||
|
||||
def test_cat(self):
|
||||
stmt = lambda y, *xs: y.eq(Cat(*xs))
|
||||
self.assertStatement(stmt, [C(0b10, 2), C(0b01, 2)], C(0b0110, 4))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue