diff --git a/magma/array.py b/magma/array.py index 2bd0f2edb..8ec6f765d 100644 --- a/magma/array.py +++ b/magma/array.py @@ -626,9 +626,6 @@ def wire(self, o, debug_info): @debug_unwire @aggregate_wireable_method def unwire(self, o=None, debug_info=None, keep_wired_when_contexts=False): - if not self._has_elaborated_children(): - return AggregateWireable.unwire(self, o, debug_info, - keep_wired_when_contexts) for i, child in self._enumerate_children(): o_i = None if o is None else o[i] child.unwire(o_i, debug_info=debug_info, diff --git a/magma/tuple.py b/magma/tuple.py index ac62eb754..ef9825585 100644 --- a/magma/tuple.py +++ b/magma/tuple.py @@ -342,9 +342,16 @@ def wire(self, o, debug_info): @debug_unwire @aggregate_wireable_method def unwire(self, o=None, debug_info=None, keep_wired_when_contexts=False): - if not self._has_elaborated_children(): - return AggregateWireable.unwire(self, o, debug_info, - keep_wired_when_contexts) + for k, t in self.items(): + if o is None: + t.unwire(debug_info=debug_info, + keep_wired_when_contexts=keep_wired_when_contexts) + elif o[k].is_input(): + o[k].unwire(t, debug_info=debug_info, + keep_wired_when_contexts=keep_wired_when_contexts) + else: + t.unwire(o[k], debug_info=debug_info, + keep_wired_when_contexts=keep_wired_when_contexts) @aggregate_wireable_method def driven(self): diff --git a/tests/test_aggregate_wireable.py b/tests/test_aggregate_wireable.py new file mode 100644 index 000000000..162a6b8a5 --- /dev/null +++ b/tests/test_aggregate_wireable.py @@ -0,0 +1,18 @@ +import pytest +import magma as m + + +@pytest.mark.parametrize('T', [m.Bits[8], m.Tuple[m.Bit, m.Bits[8]]]) +def test_aggregate_wireable_unwire(T): + class Foo(m.Circuit): + io = m.IO(I=m.In(T), O=m.Out(T)) + io.O @= io.I + assert io.O.value() is io.I + io.O.unwire(io.I) + assert io.O.value() is None + + io.O @= io.I + io.O[0] # Trigger elaboration + assert io.O.value() is io.I + io.O.unwire(io.I) + assert io.O.value() is None