ast: ensure Part
offset is unsigned.
Co-authored-by: Marcelina Kościelnicka <mwk@0x04.net>
This commit is contained in:
parent
8c4a15ab92
commit
21b5451036
|
@ -860,9 +860,14 @@ class Part(Value):
|
||||||
if not isinstance(stride, int) or stride <= 0:
|
if not isinstance(stride, int) or stride <= 0:
|
||||||
raise TypeError("Part stride must be a positive integer, not {!r}".format(stride))
|
raise TypeError("Part stride must be a positive integer, not {!r}".format(stride))
|
||||||
|
|
||||||
|
value = Value.cast(value)
|
||||||
|
offset = Value.cast(offset)
|
||||||
|
if offset.shape().signed:
|
||||||
|
raise TypeError("Part offset must be unsigned")
|
||||||
|
|
||||||
super().__init__(src_loc_at=src_loc_at)
|
super().__init__(src_loc_at=src_loc_at)
|
||||||
self.value = Value.cast(value)
|
self.value = value
|
||||||
self.offset = Value.cast(offset)
|
self.offset = offset
|
||||||
self.width = width
|
self.width = width
|
||||||
self.stride = stride
|
self.stride = stride
|
||||||
|
|
||||||
|
|
|
@ -785,6 +785,11 @@ class BitSelectTestCase(FHDLTestCase):
|
||||||
s = self.c.bit_select(self.s, 2)
|
s = self.c.bit_select(self.s, 2)
|
||||||
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 1)")
|
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 1)")
|
||||||
|
|
||||||
|
def test_offset_wrong(self):
|
||||||
|
with self.assertRaisesRegex(TypeError,
|
||||||
|
r"^Part offset must be unsigned$"):
|
||||||
|
self.c.bit_select(self.s.as_signed(), 1)
|
||||||
|
|
||||||
|
|
||||||
class WordSelectTestCase(FHDLTestCase):
|
class WordSelectTestCase(FHDLTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -817,6 +822,11 @@ class WordSelectTestCase(FHDLTestCase):
|
||||||
s = self.c.word_select(self.s, 2)
|
s = self.c.word_select(self.s, 2)
|
||||||
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 2)")
|
self.assertEqual(repr(s), "(part (const 8'd0) (sig s) 2 2)")
|
||||||
|
|
||||||
|
def test_offset_wrong(self):
|
||||||
|
with self.assertRaisesRegex(TypeError,
|
||||||
|
r"^Part offset must be unsigned$"):
|
||||||
|
self.c.word_select(self.s.as_signed(), 1)
|
||||||
|
|
||||||
|
|
||||||
class CatTestCase(FHDLTestCase):
|
class CatTestCase(FHDLTestCase):
|
||||||
def test_shape(self):
|
def test_shape(self):
|
||||||
|
|
Loading…
Reference in a new issue