if not isinstance(self.nbits, int) or self.nbits < 0:
raise TypeError("Width must be a non-negative integer, not '{!r}'".format(self.nbits))
+
+ reset_nbits = bits_for(reset, self.signed)
+ if reset != 0 and reset_nbits > self.nbits:
+ warnings.warn("Reset value {!r} requires {} bits to represent, but the signal "
+ "only has {} bits"
+ .format(reset, reset_nbits, self.nbits),
+ SyntaxWarning, stacklevel=2 + src_loc_at)
+
self.reset = int(reset)
self.reset_less = bool(reset_less)
self.assertEqual(s1.reset, 0b111)
self.assertEqual(s1.reset_less, True)
+ def test_reset_narrow(self):
+ with self.assertWarns(SyntaxWarning,
+ msg="Reset value 8 requires 4 bits to represent, but the signal only has 3 bits"):
+ Signal(3, reset=8)
+ with self.assertWarns(SyntaxWarning,
+ msg="Reset value 4 requires 4 bits to represent, but the signal only has 3 bits"):
+ Signal((3, True), reset=4)
+ with self.assertWarns(SyntaxWarning,
+ msg="Reset value -5 requires 4 bits to represent, but the signal only has 3 bits"):
+ Signal((3, True), reset=-5)
+
def test_attrs(self):
s1 = Signal()
self.assertEqual(s1.attrs, {})