From ce1a69984707b200b044d213da1405c576cd79f9 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 30 Sep 2021 13:59:02 +0100 Subject: [PATCH] add test in Repl where integers are passed in as the Value. they end up being passed to Const which ascertains how much space is needed. for proper Type 1 (ast) nmigen language abstraction, a test is needed (similar to the one in ast.Mux for bool) which converts *only* integers to Value, preserving existing behaviour. there was no unit test for this case --- nmigen/hdl/ast.py | 4 ++-- tests/test_hdl_ast.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index ef90f46..ef4a5df 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -161,8 +161,6 @@ class Value(metaclass=ABCMeta): return _InternalPart(self, offset, width, stride, src_loc_at=src_loc_at) def __Repl__(self, count, *, src_loc_at=0): return _InternalRepl(self, count, src_loc_at=src_loc_at) - def __Repl__(self, count, *, src_loc_at=0): - return _InternalRepl(self, count, src_loc_at=src_loc_at) def __Cat__(self, *args, src_loc_at=0): return _InternalCat(self, *args, src_loc_at=src_loc_at) def __Mux__(self, val1, val0): @@ -918,6 +916,8 @@ class _InternalCat(Value): @final def Repl(value, count, *, src_loc_at=0): + if not isinstance(value, Value): # rare instances where integers are passed + value = Value.cast(value) return value.__Repl__(count, src_loc_at=src_loc_at) diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 28a12a5..53985c8 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -750,6 +750,12 @@ class ReplTestCase(FHDLTestCase): s2 = Repl(Const(10), 0) self.assertEqual(s2.shape(), unsigned(0)) + def test_integer(self): + s1 = Repl(0, 3) # integer value, 1 bit long + self.assertEqual(s1.shape(), unsigned(3)) + s1 = Repl(0b1010, 3) # takes 4 bits to store, repeated 3 times => 12 bit + self.assertEqual(s1.shape(), unsigned(12)) + def test_count_wrong(self): with self.assertRaises(TypeError): Repl(Const(10), -1) -- 2.30.2