back.rtlil: only expand legalized values in Array/Part context on RHS.
authorwhitequark <whitequark@whitequark.org>
Sun, 21 Apr 2019 06:41:35 +0000 (06:41 +0000)
committerwhitequark <whitequark@whitequark.org>
Sun, 21 Apr 2019 06:43:31 +0000 (06:43 +0000)
Otherwise the following code fails to compile:

    index = Signal(1)
    array = Array(range(2))
    with m.If(0 == array[index]):
        m.d.sync += index.eq(0)

Fixes #51.

nmigen/back/rtlil.py

index fd3bfe8bd95aca80cb6e21102d09e90b8122b645..9778f4b605fb544091a08ca5951d1a7c1efe40c7 100644 (file)
@@ -299,9 +299,6 @@ class _ValueCompiler(xfrm.ValueVisitor):
     def __init__(self, state):
         self.s = state
 
-    def on_value(self, value):
-        return super().on_value(self.s.expand(value))
-
     def on_unknown(self, value):
         if value is None:
             return None
@@ -375,6 +372,9 @@ class _RHSValueCompiler(_ValueCompiler):
         (3, "m"):    "$mux",
     }
 
+    def on_value(self, value):
+        return super().on_value(self.s.expand(value))
+
     def on_Const(self, value):
         if isinstance(value.value, str):
             return "{}'{}".format(value.nbits, value.value)