back.pysim: synchronize terms with cxxrtl. NFC.
This commit is contained in:
parent
c9ac85a045
commit
e012e62ade
|
@ -253,16 +253,16 @@ class _SimulatorState:
|
||||||
return self.slots[self.get_signal(signal)]
|
return self.slots[self.get_signal(signal)]
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
awoken_any = False
|
converged = True
|
||||||
for signal_state in self.pending:
|
for signal_state in self.pending:
|
||||||
if signal_state.commit():
|
if signal_state.commit():
|
||||||
if signal_state.wakeup():
|
if signal_state.wakeup():
|
||||||
awoken_any = True
|
converged = False
|
||||||
if self.waveform_writer is not None:
|
if self.waveform_writer is not None:
|
||||||
self.waveform_writer.update(self.timestamp,
|
self.waveform_writer.update(self.timestamp,
|
||||||
signal_state.signal, signal_state.curr)
|
signal_state.signal, signal_state.curr)
|
||||||
self.pending.clear()
|
self.pending.clear()
|
||||||
return awoken_any
|
return converged
|
||||||
|
|
||||||
def advance(self):
|
def advance(self):
|
||||||
nearest_processes = set()
|
nearest_processes = set()
|
||||||
|
@ -1006,31 +1006,31 @@ class Simulator:
|
||||||
for process in self._processes:
|
for process in self._processes:
|
||||||
process.reset()
|
process.reset()
|
||||||
|
|
||||||
def _delta(self):
|
def _real_step(self):
|
||||||
"""Perform a delta cycle.
|
"""Step the simulation.
|
||||||
|
|
||||||
Performs the two phases of a delta cycle:
|
|
||||||
1. run and suspend every non-waiting process once, queueing signal changes;
|
|
||||||
2. commit every queued signal change, waking up any waiting process.
|
|
||||||
"""
|
|
||||||
for process in self._processes:
|
|
||||||
if process.runnable:
|
|
||||||
process.runnable = False
|
|
||||||
process.run()
|
|
||||||
|
|
||||||
return self._state.commit()
|
|
||||||
|
|
||||||
def _settle(self):
|
|
||||||
"""Settle the simulation.
|
|
||||||
|
|
||||||
Run every process and commit changes until a fixed point is reached. If there is
|
Run every process and commit changes until a fixed point is reached. If there is
|
||||||
an unstable combinatorial loop, this function will never return.
|
an unstable combinatorial loop, this function will never return.
|
||||||
"""
|
"""
|
||||||
while self._delta():
|
# Performs the two phases of a delta cycle in a loop:
|
||||||
pass
|
converged = False
|
||||||
|
while not converged:
|
||||||
|
# 1. eval: run and suspend every non-waiting process once, queueing signal changes
|
||||||
|
for process in self._processes:
|
||||||
|
if process.runnable:
|
||||||
|
process.runnable = False
|
||||||
|
process.run()
|
||||||
|
|
||||||
|
# 2. commit: apply every queued signal change, waking up any waiting processes
|
||||||
|
converged = self._state.commit()
|
||||||
|
|
||||||
|
# TODO(nmigen-0.4): replace with _real_step
|
||||||
|
@deprecated("instead of `sim.step()`, use `sim.advance()`")
|
||||||
def step(self):
|
def step(self):
|
||||||
"""Step the simulation.
|
return self.advance()
|
||||||
|
|
||||||
|
def advance(self):
|
||||||
|
"""Advance the simulation.
|
||||||
|
|
||||||
Run every process and commit changes until a fixed point is reached, then advance time
|
Run every process and commit changes until a fixed point is reached, then advance time
|
||||||
to the closest deadline (if any). If there is an unstable combinatorial loop,
|
to the closest deadline (if any). If there is an unstable combinatorial loop,
|
||||||
|
@ -1038,7 +1038,7 @@ class Simulator:
|
||||||
|
|
||||||
Returns ``True`` if there are any active processes, ``False`` otherwise.
|
Returns ``True`` if there are any active processes, ``False`` otherwise.
|
||||||
"""
|
"""
|
||||||
self._settle()
|
self._real_step()
|
||||||
self._state.advance()
|
self._state.advance()
|
||||||
return any(not process.passive for process in self._processes)
|
return any(not process.passive for process in self._processes)
|
||||||
|
|
||||||
|
@ -1049,7 +1049,7 @@ class Simulator:
|
||||||
and may change their status using the ``yield Passive()`` and ``yield Active()`` commands.
|
and may change their status using the ``yield Passive()`` and ``yield Active()`` commands.
|
||||||
Processes compiled from HDL and added with :meth:`add_clock` are always passive.
|
Processes compiled from HDL and added with :meth:`add_clock` are always passive.
|
||||||
"""
|
"""
|
||||||
while self.step():
|
while self.advance():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_until(self, deadline, *, run_passive=False):
|
def run_until(self, deadline, *, run_passive=False):
|
||||||
|
@ -1062,7 +1062,7 @@ class Simulator:
|
||||||
If the simulation stops advancing, this function will never return.
|
If the simulation stops advancing, this function will never return.
|
||||||
"""
|
"""
|
||||||
assert self._state.timestamp <= deadline
|
assert self._state.timestamp <= deadline
|
||||||
while (self.step() or run_passive) and self._state.timestamp < deadline:
|
while (self.advance() or run_passive) and self._state.timestamp < deadline:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def write_vcd(self, vcd_file, gtkw_file=None, *, traces=()):
|
def write_vcd(self, vcd_file, gtkw_file=None, *, traces=()):
|
||||||
|
|
Loading…
Reference in a new issue