From: whitequark Date: Thu, 13 Dec 2018 18:28:11 +0000 (+0000) Subject: back.pysim: allow multiple registered handlers per signal. X-Git-Tag: working~287 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a7ebc02bdd264ec7a5b4115048de7c84ac92b443;p=nmigen.git back.pysim: allow multiple registered handlers per signal. --- 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: