From: Luke Kenneth Casson Leighton Date: Thu, 30 Sep 2021 12:59:02 +0000 (+0100) Subject: add test in Repl where integers are passed in as the Value. they end up being X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c90a275bc704df2c1704c65970838bb5e893dab7;p=nmigen.git 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 --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 5f3f5bc..b528fcd 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): @@ -922,6 +920,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 3d5dc8c..a792f97 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -746,6 +746,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)