back.pysim: support async reset.
authorwhitequark <cz@m-labs.hk>
Sat, 26 Jan 2019 18:07:43 +0000 (18:07 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 26 Jan 2019 18:07:43 +0000 (18:07 +0000)
nmigen/back/pysim.py

index 58e9d8c789b0908a7ad3033624073133379b02e9..530ee7dfc411dd3087219eb480685c5d14d1014f 100644 (file)
@@ -550,10 +550,21 @@ class Simulator:
                     self._domain_signals[domain] |= signals_bits
 
             statements = []
-            for signal in fragment.iter_comb():
-                statements.append(signal.eq(signal.reset))
-            for domain, signal in fragment.iter_sync():
-                statements.append(signal.eq(signal))
+            for domain, signals in fragment.drivers.items():
+                reset_stmts = []
+                hold_stmts  = []
+                for signal in signals:
+                    reset_stmts.append(signal.eq(signal.reset))
+                    hold_stmts .append(signal.eq(signal))
+
+                if domain is None:
+                    statements += reset_stmts
+                else:
+                    if self._domains[domain].async_reset:
+                        statements.append(Switch(self._domains[domain].rst,
+                            {0: hold_stmts, 1: reset_stmts}))
+                    else:
+                        statements += hold_stmts
             statements += fragment.statements
 
             compiler = _StatementCompiler(self._signal_slots)