Skip to main content

rustdv_sim/
rustdv_sim.rs

1//! # rustdv-sim
2//!
3//! The cocotb-analog core (design-doc §4): a bespoke single-threaded
4//! executor driven by simulator callbacks (D4.1 — not tokio), the task
5//! model, the trigger inventory, typed signal handles with buffered
6//! writes, `Clock`, and sim-aware `Event`/`Lock`/`Queue`.
7//!
8//! Control-flow contract (§4.1): a GPI/VPI callback fires → subscribed
9//! tasks are woken → the run queue is drained to exhaustion
10//! ([`Executor::run_until_idle`]) → control returns to the simulator.
11
12// Test executables need vpi_* symbol definitions (the simulator provides
13// them for the real cdylib) — see rustdv-vpi-stubs.
14#[cfg(test)]
15use rustdv_vpi_stubs as _;
16
17pub mod clock;
18pub mod combinators;
19pub mod executor;
20pub mod handle;
21pub mod log;
22pub mod path;
23pub mod phase;
24pub mod queue;
25pub mod rng;
26pub mod simulator_trace;
27pub mod sync;
28pub mod testing;
29pub mod time;
30pub mod triggers;
31pub mod verilator_trace;
32
33pub use clock::Clock;
34pub use combinators::{Either, TimeoutError, first2, join_all, join2, with_timeout};
35pub use executor::{Executor, TaskError, TaskHandle, TaskId, TaskState, spawn, spawn_named};
36pub use handle::{
37    AggregateHandle, HierarchyHandle, LogicHandle, RealHandle, SimHandle, StringHandle,
38};
39pub use path::RustdvPath;
40pub use phase::{next_time_step, read_only, read_write, service_read_only};
41pub use queue::Queue;
42pub use rng::Rng;
43pub use sync::{Event, Lock, LockGuard};
44pub use time::{SimDuration, sim_time_ns, sim_time_steps};
45pub use triggers::{NullTrigger, Timer};
46
47pub use rustdv_gpi::{BigUint, HandleError, Logic, LogicArray, ValueError};
48
49/// Initialize the sim context: install a fresh executor and phase hub on
50/// this thread. Called once by the runner at start-of-simulation.
51pub fn init() -> Executor {
52    phase::init_hub();
53    executor::init()
54}