From cc115013ea88f435c83d08c5cc8c0a294154c922 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 13 Dec 2018 18:28:11 +0000 Subject: [PATCH] back.pysim: allow multiple registered handlers per signal. --- nmigen/back/pysim.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index fc298cf..5b0f352 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -198,7 +198,7 @@ class Simulator: self._passive = set() # {process} self._suspended = {} # process -> until - self._handlers = ValueDict() # Signal -> lambda + self._handlers = ValueDict() # Signal -> set(lambda) self._vcd_file = vcd_file self._vcd_writer = None @@ -240,6 +240,11 @@ class Simulator: return "{}_{}".format(name, signal.name) return signal.name + def _add_handler(self, signal, handler): + if signal not in self._handlers: + self._handlers[signal] = set() + self._handlers[signal].add(handler) + def __enter__(self): if self._vcd_file: self._vcd_writer = VCDWriter(self._vcd_file, timescale="100 ps", @@ -280,11 +285,11 @@ class Simulator: compiler = _StatementCompiler() handler = compiler(fragment.statements) for signal in compiler.sensitivity: - self._handlers[signal] = handler + self._add_handler(signal, handler) for domain, cd in fragment.domains.items(): - self._handlers[cd.clk] = handler + self._add_handler(cd.clk, handler) if cd.rst is not None: - self._handlers[cd.rst] = handler + self._add_handler(cd.rst, handler) self._user_signals = self._signals - self._comb_signals - self._sync_signals @@ -304,7 +309,8 @@ class Simulator: while self._state.curr_dirty: signal = self._state.curr_dirty.pop() if signal in self._handlers: - self._handlers[signal](self._state) + for handler in self._handlers[signal]: + handler(self._state) for signal in self._state.next_dirty: if signal in self._comb_signals or signal in self._user_signals: -- 2.30.2