3 from collections
.abc
import Iterable
4 from ...hdl
.cd
import ClockDomain
5 from ...hdl
.ir
import Fragment
9 __all__
= ["run_simulation", "passive"]
12 def run_simulation(fragment_or_module
, generators
, clocks
={"sync": 10}, vcd_name
=None,
13 special_overrides
={}):
14 assert not special_overrides
16 if hasattr(fragment_or_module
, "get_fragment"):
17 fragment
= fragment_or_module
.get_fragment()
19 fragment
= fragment_or_module
21 fragment
= Fragment
.get(fragment
, platform
=None)
23 if not isinstance(generators
, dict):
24 generators
= {"sync": generators
}
25 if "sync" not in fragment
.domains
:
26 fragment
.add_domains(ClockDomain("sync"))
28 sim
= Simulator(fragment
)
29 for domain
, period
in clocks
.items():
30 sim
.add_clock(period
/ 1e9
, domain
=domain
)
31 for domain
, processes
in generators
.items():
36 if isinstance(processes
, Iterable
) and not inspect
.isgenerator(processes
):
37 for process
in processes
:
38 sim
.add_sync_process(wrap(process
), domain
=domain
)
40 sim
.add_sync_process(wrap(processes
), domain
=domain
)
42 if vcd_name
is not None:
43 with sim
.write_vcd(vcd_name
):
49 def passive(generator
):
50 @functools.wraps(generator
)
51 def wrapper(*args
, **kwargs
):
53 yield from generator(*args
, **kwargs
)