back.rtlil: do not consider unreachable array elements when legalizing.
authorwhitequark <whitequark@whitequark.org>
Wed, 1 Jan 2020 15:26:05 +0000 (15:26 +0000)
committerwhitequark <whitequark@whitequark.org>
Wed, 1 Jan 2020 15:26:05 +0000 (15:26 +0000)
Otherwise we produce invalid RTLIL.

nmigen/back/rtlil.py

index 9869c61d77c15c3d78a8a094056072247612f42b..4a994fd4ffd9f55e8bab6dd35005fd85f262dfb7 100644 (file)
@@ -374,7 +374,9 @@ class _ValueCompiler(xfrm.ValueVisitor):
                 elem = value.elems[-1]
             return self.match_shape(elem, *value.shape())
         else:
-            raise LegalizeValue(value.index, range(len(value.elems)), value.src_loc)
+            max_index = 1 << len(value.index)
+            max_elem  = len(value.elems)
+            raise LegalizeValue(value.index, range(min(max_index, max_elem)), value.src_loc)
 
 
 class _RHSValueCompiler(_ValueCompiler):