Before this commit, each simulation engine (which is only pysim at
the moment, but also cxxsim soon) was a subclass of SimulatorCore,
and every simulation engine module would essentially duplicate
the complete structure of a simulator, with code partially shared.
This was a really bad idea: it was inconvenient to use, with
downstream code having to branch between e.g. PySettle and CxxSettle;
it had no well-defined external interface; it had multiple virtually
identical entry points; and it had no separation between simulation
algorithms and glue code.
This commit completely rearranges simulation code.
1. sim._base defines internal simulation interfaces. The clarity of
these internal interfaces is important because simulation
engines mix and match components to provide a consistent API
regardless of the chosen engine.
2. sim.core defines the external simulation interface: the commands
and the simulator facade. The facade provides a single entry
point and, when possible, validates or lowers user input.
It also imports built-in simulation engines by their symbolic
name, avoiding eager imports of pyvcd or ctypes.
3. sim.xxxsim (currently, only sim.pysim) defines the simulator
implementation: time and state management, process scheduling,
and waveform dumping.
The new simulator structure has none of the downsides of the old one.
See #324.
68 lines
1.4 KiB
Python
68 lines
1.4 KiB
Python
__all__ = ["BaseProcess", "BaseSignalState", "BaseSimulation", "BaseEngine"]
|
|
|
|
|
|
class BaseProcess:
|
|
__slots__ = ()
|
|
|
|
def __init__(self):
|
|
self.reset()
|
|
|
|
def reset(self):
|
|
self.runnable = False
|
|
self.passive = True
|
|
|
|
def run(self):
|
|
raise NotImplementedError
|
|
|
|
|
|
class BaseSignalState:
|
|
__slots__ = ()
|
|
|
|
signal = NotImplemented
|
|
|
|
curr = NotImplemented
|
|
next = NotImplemented
|
|
|
|
def set(self, value):
|
|
raise NotImplementedError
|
|
|
|
|
|
class BaseSimulation:
|
|
def reset(self):
|
|
raise NotImplementedError
|
|
|
|
def get_signal(self, signal):
|
|
raise NotImplementedError
|
|
|
|
slots = NotImplemented
|
|
|
|
def add_trigger(self, process, signal, *, trigger=None):
|
|
raise NotImplementedError
|
|
|
|
def remove_trigger(self, process, signal):
|
|
raise NotImplementedError
|
|
|
|
def wait_interval(self, process, interval):
|
|
raise NotImplementedError
|
|
|
|
|
|
class BaseEngine:
|
|
def add_coroutine_process(self, process, *, default_cmd):
|
|
raise NotImplementedError
|
|
|
|
def add_clock_process(self, clock, *, phase, period):
|
|
raise NotImplementedError
|
|
|
|
def reset(self):
|
|
raise NotImplementedError
|
|
|
|
@property
|
|
def now(self):
|
|
raise NotImplementedError
|
|
|
|
def advance(self):
|
|
raise NotImplementedError
|
|
|
|
def write_vcd(self, *, vcd_file, gtkw_file, traces):
|
|
raise NotImplementedError
|