1 """Run-time selection of simulator engine
5 from nmutil.sim_tmp_alternative import Simulator
7 Then, use :py:class:`Simulator` as usual.
9 This should be backwards compatible to old developer versions of nMigen.
11 To use cxxsim, export ``NMIGEN_SIM_MODE=cxxsim`` from the shell.
12 Be sure to check out the ``cxxsim`` branch of nMigen, and update yosys
13 to the latest commit as well.
15 To use pysim, just keep ``NMIGEN_SIM_MODE`` unset.
16 Alternatively, export ``NMIGEN_SIM_MODE=pysim``.
20 $ export NMIGEN_SIM_MODE=... # pysim or cxxsim, default is pysim
25 $ NMIGEN_SIM_MODE=... python ...
31 from nmigen
.sim
import Simulator
as RealSimulator
32 detected_new_api
= True
34 detected_new_api
= False
36 from nmigen
.sim
.pysim
import Simulator
as RealSimulator
38 from nmigen
.back
.pysim
import Simulator
as RealSimulator
40 nmigen_sim_environ_variable
= os
.environ
.get("NMIGEN_SIM_MODE") \
42 """Detected run-time engine from environment"""
45 def Simulator(*args
, **kwargs
):
46 """Wrapper that allows run-time selection of simulator engine"""
48 kwargs
['engine'] = nmigen_sim_environ_variable
49 return RealSimulator(*args
, **kwargs
)
52 def is_engine_cxxsim():
53 """Returns ``True`` if the selected engine is cxxsim"""
54 return nmigen_sim_environ_variable
== "cxxsim"
57 def is_engine_pysim():
58 """Returns ``True`` if the selected engine is pysim"""
59 return nmigen_sim_environ_variable
== "pysim"
62 nmigen_sim_top_module
= "top." if is_engine_pysim() else ""
63 """Work-around for cxxsim not defining the top-level module"""