Expand description
§rustdv-gpi
Safe wrapper over the simulator programming interface (design-doc §3.3). Invariants upheld here so everything above is safe Rust:
- Handles are opaque and non-null; fallible acquisition is
Result. - Object-handle lifetime = simulation lifetime (freely
Copyable IDs). Callback handles invalidate on removal/fire — modeled by RAII (CallbackHandle): dropping an unfired handle removes the callback. - Strings are copied at the boundary, every call.
- No unwinding across FFI: every trampoline wraps the closure in
catch_unwind; panics are routed to the panic sink. - Callback user-data ownership: an
Rcwhose C-side reference is reclaimed exactly once (on fire for one-shots, on removal otherwise).
Thread affinity (§3.4): all types here hold raw pointers and are
therefore !Send/!Sync — the compiler rejects moving them off the
simulator thread.
Re-exports§
pub use value::Logic;pub use value::LogicArray;
Modules§
- value
- 4-state value types: port of cocotb’s
Logic/LogicArray(cocotb: types/, design-doc mapping row 23). Conversion failures areResults, not exceptions.
Structs§
- Callback
Handle - RAII callback registration. Dropping an unfired/live handle removes the simulator callback — this is what makes drop-based task cancellation (design-doc §4.6) clean up trigger registrations for free.
- Hierarchy
Handle - A module/scope handle. Port of cocotb’s HierarchyObject
(cocotb: handle.py), with
Result-returning lookup (mapping row 19). - Logic
Handle - A value-bearing signal handle (net/reg/var). Port of cocotb’s
LogicObject surface: explicit
get()/set()(mapping row 20). Buffered-write semantics live a layer up in rustdv-sim; the methods here apply values immediately. - ObjHandle
- Raw non-null simulator object handle. Valid for the whole simulation
(invariant 2), hence
Copy.!Sendbecause it wraps a raw pointer.
Enums§
- AnyHandle
- Any simulator object, classified by type (design-doc §3.3 downcasting).
- Handle
Error - Value
Error
Functions§
- finish
- End the simulation (vpi_control(vpiFinish)).
- register_
end_ of_ simulation - One-shot callback at end of simulation.
- register_
next_ sim_ time - One-shot callback at the next simulation time step.
- register_
read_ only - One-shot callback at the next ReadOnly synch point.
- register_
read_ write - One-shot callback at the next ReadWrite synch point.
- register_
start_ of_ simulation - One-shot callback at start of simulation (the bootstrap hook).
- register_
timer - One-shot callback after
stepsprecision units (cbAfterDelay). - register_
value_ change - Recurring callback on any value change of
sig(cbValueChange). The closure reads the signal itself; edge filtering happens in rustdv-sim. - set_
panic_ sink - Install the handler invoked when a callback closure panics (the runner routes this to “fail the current test”, mirroring cocotb catching BaseException per task).
- sim_
time_ steps - Current simulation time in simulator precision steps.
- time_
precision - Simulator time precision as a power of ten (e.g. -9 = 1 ns).
- top_
module - The first top-level module (the DUT in single-top designs).
- top_
modules - All top-level modules in the design.