hdl.ast: deprecate UserValue in favor of ValueCastable.

Closes #527.
This commit is contained in:
whitequark 2020-11-06 02:21:53 +00:00
parent c9fd000103
commit bde37fe2f2
3 changed files with 27 additions and 15 deletions

View file

@ -1009,20 +1009,24 @@ class MockUserValue(UserValue):
class UserValueTestCase(FHDLTestCase):
def test_shape(self):
uv = MockUserValue(1)
self.assertEqual(uv.shape(), unsigned(1))
self.assertIsInstance(uv.shape(), Shape)
uv.lowered = 2
self.assertEqual(uv.shape(), unsigned(1))
self.assertEqual(uv.lower_count, 1)
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
uv = MockUserValue(1)
self.assertEqual(uv.shape(), unsigned(1))
self.assertIsInstance(uv.shape(), Shape)
uv.lowered = 2
self.assertEqual(uv.shape(), unsigned(1))
self.assertEqual(uv.lower_count, 1)
def test_lower_to_user_value(self):
uv = MockUserValue(MockUserValue(1))
self.assertEqual(uv.shape(), unsigned(1))
self.assertIsInstance(uv.shape(), Shape)
uv.lowered = MockUserValue(2)
self.assertEqual(uv.shape(), unsigned(1))
self.assertEqual(uv.lower_count, 1)
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
uv = MockUserValue(MockUserValue(1))
self.assertEqual(uv.shape(), unsigned(1))
self.assertIsInstance(uv.shape(), Shape)
uv.lowered = MockUserValue(2)
self.assertEqual(uv.shape(), unsigned(1))
self.assertEqual(uv.lower_count, 1)
class MockValueCastableChanges(ValueCastable):

View file

@ -1,5 +1,7 @@
# nmigen: UnusedElaboratable=no
import warnings
from nmigen.hdl.ast import *
from nmigen.hdl.cd import *
from nmigen.hdl.ir import *
@ -614,7 +616,9 @@ class UserValueTestCase(FHDLTestCase):
def setUp(self):
self.s = Signal()
self.c = Signal()
self.uv = MockUserValue(self.s)
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
self.uv = MockUserValue(self.s)
def test_lower(self):
sync = ClockDomain()
@ -645,6 +649,8 @@ class UserValueRecursiveTestCase(UserValueTestCase):
def setUp(self):
self.s = Signal()
self.c = Signal()
self.uv = MockUserValue(MockUserValue(self.s))
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
self.uv = MockUserValue(MockUserValue(self.s))
# inherit the test_lower method from UserValueTestCase because the checks are the same