pub struct Simulator<B: SimBackend = DefaultBackend> { /* private fields */ }Expand description
The core logic evaluation engine.
Encapsulates the backend, the original SIR program, and an optional VCD writer. Provides low-level, event-driven control.
The default type parameter B = DefaultBackend means that bare Simulator
uses the custom native backend on a matching host and Cranelift for
cross-codegen builds or unsupported hosts.
Implementations§
Source§impl<B: SimBackend> Simulator<B>
impl<B: SimBackend> Simulator<B>
pub fn with_backend_and_program( backend: B, program: RuntimeProgram, warnings: Vec<CompilationWarning>, ) -> Self
pub fn drain_runtime_events(&mut self) -> Vec<RuntimeEvent>
pub fn drain_runtime_events_with_context( &mut self, ctx: RuntimeFormatContext<'_>, ) -> Vec<RuntimeEvent>
pub fn runtime_event_drain(&mut self) -> Option<RuntimeEventDrain>
Sourcepub fn program(&self) -> &RuntimeProgram
pub fn program(&self) -> &RuntimeProgram
Returns a reference to the compiled SIR program.
Sourcepub fn backend_ref(&self) -> &B
pub fn backend_ref(&self) -> &B
Returns a reference to the backend (for signal/event resolution).
Sourcepub fn warnings(&self) -> &[CompilationWarning]
pub fn warnings(&self) -> &[CompilationWarning]
Returns warnings emitted during compilation.
Sourcepub fn dump(&mut self, timestamp: u64)
pub fn dump(&mut self, timestamp: u64)
Captures the current state of all signals and writes them to the VCD file.
Sourcepub fn set<T: Copy>(&mut self, signal: SignalRef, val: T)
pub fn set<T: Copy>(&mut self, signal: SignalRef, val: T)
Sets a signal value and marks combinational logic as dirty.
Sourcepub fn set_wide(&mut self, signal: SignalRef, val: BigUint)
pub fn set_wide(&mut self, signal: SignalRef, val: BigUint)
Sets a wide signal value and marks combinational logic as dirty.
Sourcepub fn set_four_state(&mut self, signal: SignalRef, val: BigUint, mask: BigUint)
pub fn set_four_state(&mut self, signal: SignalRef, val: BigUint, mask: BigUint)
Sets a four-state signal value and marks combinational logic as dirty.
Sourcepub fn modify<F>(&mut self, f: F) -> Result<(), RuntimeErrorCode>
pub fn modify<F>(&mut self, f: F) -> Result<(), RuntimeErrorCode>
Modifies internal state via a callback and marks combinational logic as dirty.
Sourcepub fn tick(&mut self, event: B::Event) -> Result<(), RuntimeErrorCode>
pub fn tick(&mut self, event: B::Event) -> Result<(), RuntimeErrorCode>
Manually triggers a clock or event to process sequential logic.
Sourcepub fn signal(&self, path: &str) -> SignalRef
pub fn signal(&self, path: &str) -> SignalRef
Resolves a signal path into a performance-optimized SignalRef.
This handle allows for direct memory access without HashMap lookups.
Sourcepub fn try_signal(&self, path: &str) -> Result<SignalRef, AddrLookupError>
pub fn try_signal(&self, path: &str) -> Result<SignalRef, AddrLookupError>
Try to resolve a signal path. Returns Err if the path is not found or ambiguous.
Sourcepub fn try_event(&self, port: &str) -> Result<B::Event, AddrLookupError>
pub fn try_event(&self, port: &str) -> Result<B::Event, AddrLookupError>
Try to resolve a port name to an event handle.
Sourcepub fn get_as<T: Default + Copy>(&mut self, signal: SignalRef) -> T
pub fn get_as<T: Default + Copy>(&mut self, signal: SignalRef) -> T
Retrieves the current value as a fixed-size type without BigUint allocation.
Lazily evaluates combinational logic if the state is dirty.
Sourcepub fn get(&mut self, signal: SignalRef) -> BigUint
pub fn get(&mut self, signal: SignalRef) -> BigUint
Retrieves the current value of a variable using a pre-resolved SignalRef handle.
Lazily evaluates combinational logic if the state is dirty.
Sourcepub fn get_four_state(&mut self, signal: SignalRef) -> (BigUint, BigUint)
pub fn get_four_state(&mut self, signal: SignalRef) -> (BigUint, BigUint)
Retrieves the current 4-state value (value, mask) of a variable using a SignalRef handle.
Lazily evaluates combinational logic if the state is dirty.
Sourcepub fn eval_comb(&mut self) -> Result<(), RuntimeErrorCode>
pub fn eval_comb(&mut self) -> Result<(), RuntimeErrorCode>
Directly execute combinational logic evaluation.
Sourcepub fn memory_as_ptr(&self) -> (*const u8, usize)
pub fn memory_as_ptr(&self) -> (*const u8, usize)
Returns a raw pointer to the backend memory and its total size in bytes.
Sourcepub fn memory_as_mut_ptr(&mut self) -> (*mut u8, usize)
pub fn memory_as_mut_ptr(&mut self) -> (*mut u8, usize)
Returns a mutable raw pointer to the backend memory and its total size in bytes.
Sourcepub fn stable_region_size(&self) -> usize
pub fn stable_region_size(&self) -> usize
Returns the stable region size in bytes.
Sourcepub fn layout(&self) -> &MemoryLayout
pub fn layout(&self) -> &MemoryLayout
Returns a reference to the memory layout.
Sourcepub fn take_vcd_writer(&mut self) -> Option<VcdWriter>
pub fn take_vcd_writer(&mut self) -> Option<VcdWriter>
Take ownership of the VCD writer, if one was configured at build time.
Builders create the writer themselves so that layout selection can account for VCD recording; callers building handles around a backend use this to keep tracing alive without rebuilding descriptors.
Sourcepub fn build_vcd_descs(&self, four_state_mode: bool) -> Vec<VcdSignalDesc>
pub fn build_vcd_descs(&self, four_state_mode: bool) -> Vec<VcdSignalDesc>
Build VCD signal descriptors for all instances.
The returned descriptors are self-contained (no IR references) and can
be cached alongside SharedJitCode so that VCD works on cache-hit
paths without the original RuntimeProgram.
Sourcepub fn named_signals(&self) -> Vec<NamedSignal>
pub fn named_signals(&self) -> Vec<NamedSignal>
Returns all ports of the top-level module with their resolved signal references.
Sourcepub fn instance_signals(
&self,
instance_path: &[(&str, usize)],
) -> Vec<NamedSignal>
pub fn instance_signals( &self, instance_path: &[(&str, usize)], ) -> Vec<NamedSignal>
Returns all signals for the instance at the given hierarchical path.
The path is specified as a slice of (instance_name, index) pairs.
Returns an empty Vec if the path does not exist.
Sourcepub fn named_events(&self) -> Vec<NamedEvent<B>>
pub fn named_events(&self) -> Vec<NamedEvent<B>>
Returns all events (clock/reset signals) with their IDs and event references.
Sourcepub fn tick_by_id(&mut self, event_id: usize) -> Result<(), RuntimeErrorCode>
pub fn tick_by_id(&mut self, event_id: usize) -> Result<(), RuntimeErrorCode>
Triggers a clock/event by its numeric ID.
Sourcepub fn tick_by_id_n(
&mut self,
event_id: usize,
count: u32,
) -> Result<(), RuntimeErrorCode>
pub fn tick_by_id_n( &mut self, event_id: usize, count: u32, ) -> Result<(), RuntimeErrorCode>
Triggers a clock/event N times by its numeric ID. Avoids repeated cross-boundary calls when used from FFI.
Sourcepub fn child_signal(
&self,
instance_path: &[(&str, usize)],
var: &str,
) -> SignalRef
pub fn child_signal( &self, instance_path: &[(&str, usize)], var: &str, ) -> SignalRef
Resolves a signal inside a child instance.
Sourcepub fn try_child_signal(
&self,
instance_path: &[(&str, usize)],
var: &str,
) -> Result<SignalRef, AddrLookupError>
pub fn try_child_signal( &self, instance_path: &[(&str, usize)], var: &str, ) -> Result<SignalRef, AddrLookupError>
Try to resolve a signal inside a child instance.
Sourcepub fn named_hierarchy(&self) -> InstanceHierarchy
pub fn named_hierarchy(&self) -> InstanceHierarchy
Returns the full instance hierarchy starting from the top module.
Source§impl Simulator
impl Simulator
pub fn builder<'a>( code: &'a str, top: &'a str, ) -> SimulatorBuilder<'a, Simulator>
pub fn from_sources<'a>( sources: Vec<(&'a str, &'a Path)>, top: &'a str, ) -> SimulatorBuilder<'a, Simulator>
Sourcepub fn from_frontend(
artifact: FrontendArtifact,
) -> SimulatorBuilder<'static, Simulator>
pub fn from_frontend( artifact: FrontendArtifact, ) -> SimulatorBuilder<'static, Simulator>
Low-level adapter hook for an elaborated external frontend artifact.
Frontend crates should wrap this with a constructor named for their
own artifact type instead of exposing
celox_frontend_sdk::FrontendArtifact to applications.
Sourcepub fn from_frontend_with_testbench<'a>(
artifact: FrontendArtifact,
sources: Vec<(&'a str, &'a Path)>,
top: &'a str,
) -> SimulatorBuilder<'a, Simulator>
pub fn from_frontend_with_testbench<'a>( artifact: FrontendArtifact, sources: Vec<(&'a str, &'a Path)>, top: &'a str, ) -> SimulatorBuilder<'a, Simulator>
Low-level adapter hook for a Veryl testbench around an external module.
Source§impl Simulator<JitBackend>
impl Simulator<JitBackend>
Returns the shared compiled JIT code, allowing it to be reused for creating additional simulator instances without recompilation.
Sourcepub fn into_backend(self) -> JitBackend
pub fn into_backend(self) -> JitBackend
Consume the simulator and return the inner JIT backend.
Source§impl Simulator<WasmBackend>
impl Simulator<WasmBackend>
Sourcepub fn into_backend(self) -> WasmBackend
pub fn into_backend(self) -> WasmBackend
Consume the simulator and return the inner Wasmtime backend.
Source§impl Simulator<TieredBackend>
impl Simulator<TieredBackend>
Sourcepub fn is_compiled(&self) -> bool
pub fn is_compiled(&self) -> bool
Whether this tiered simulation has adopted its compiled tier.
False while background compilation is still running or after it failed (the interpreter then remains the permanent tier).
Sourcepub fn tiered_execution_stats(&self) -> TieredExecutionStats
pub fn tiered_execution_stats(&self) -> TieredExecutionStats
Return deterministic tier lifecycle and evaluation measurements.
The snapshot contains counts rather than ad-hoc wall-clock samples; use a statistical benchmark harness to measure elapsed time.
Sourcepub fn start_tiered_execution_timing(&mut self)
pub fn start_tiered_execution_timing(&mut self)
Start opt-in wall-clock measurement from workload execution to promotion. Ordinary tiered simulation does not read the host clock.
Sourcepub fn finish_tiered_execution_timing(
&mut self,
) -> Option<TieredExecutionTiming>
pub fn finish_tiered_execution_timing( &mut self, ) -> Option<TieredExecutionTiming>
Stop tiered execution timing and return the promotion interval.
Sourcepub fn promotion_error(&self) -> Option<&SimulatorError>
pub fn promotion_error(&self) -> Option<&SimulatorError>
Why promotion has not happened yet, for diagnostics.
Sourcepub fn cancel_background_compilation(&mut self) -> bool
pub fn cancel_background_compilation(&mut self) -> bool
Request cancellation of background compilation.
The simulation stays on the interpreter permanently and
Simulator::promotion_error reports the cancellation. Returns
whether a background compilation was still pending.
Sourcepub fn into_backend(self) -> TieredBackend
pub fn into_backend(self) -> TieredBackend
Consume the simulator and return the inner tiered backend.
Source§impl Simulator<NativeBackend>
impl Simulator<NativeBackend>
Returns the shared compiled native code, allowing it to be reused for creating additional simulator instances without recompilation.
Sourcepub fn start_native_execution_timing(&mut self)
pub fn start_native_execution_timing(&mut self)
Start measuring time spent inside generated native simulator functions.
The measurement is disabled by default, so ordinary simulation does not read the host clock. Native tick loops are measured once per host-side batch rather than once per simulated tick.
Sourcepub fn finish_native_execution_timing(
&mut self,
) -> Option<NativeExecutionTiming>
pub fn finish_native_execution_timing( &mut self, ) -> Option<NativeExecutionTiming>
Stop native execution timing and return the accumulated measurement.
Create a simulator from pre-compiled shared native code.
Sourcepub fn into_backend(self) -> NativeBackend
pub fn into_backend(self) -> NativeBackend
Consume the simulator and return the inner native backend.
Trait Implementations§
Source§impl<B: SimBackend> Debug for Simulator<B>
impl<B: SimBackend> Debug for Simulator<B>
Source§impl<B: SimBackend> SimulationExecutor for Simulator<B>
impl<B: SimBackend> SimulationExecutor for Simulator<B>
type Backend = B
fn backend(&self) -> &B
fn backend_mut(&mut self) -> &mut B
fn eval_comb(&mut self) -> Result<(), RuntimeErrorCode>
fn eval_apply_ff_at(&mut self, event: B::Event) -> Result<(), RuntimeErrorCode>
fn eval_only_ff_at(&mut self, event: B::Event) -> Result<(), RuntimeErrorCode>
fn apply_ff_at(&mut self, event: B::Event) -> Result<(), RuntimeErrorCode>
Source§fn stage_external_event(
&mut self,
event: B::Event,
_timestamp: u64,
) -> Result<(), RuntimeErrorCode>
fn stage_external_event( &mut self, event: B::Event, _timestamp: u64, ) -> Result<(), RuntimeErrorCode>
Source§fn fire_external_event(
&mut self,
event: B::Event,
timestamp: u64,
) -> Result<(), RuntimeErrorCode>
fn fire_external_event( &mut self, event: B::Event, timestamp: u64, ) -> Result<(), RuntimeErrorCode>
Source§fn finish_timed_step(&mut self, timestamp: u64)
fn finish_timed_step(&mut self, timestamp: u64)
Auto Trait Implementations§
impl<B = NativeBackend> !RefUnwindSafe for Simulator<B>
impl<B = NativeBackend> !Sync for Simulator<B>
impl<B = NativeBackend> !UnwindSafe for Simulator<B>
impl<B> Freeze for Simulator<B>
impl<B> Send for Simulator<B>
impl<B> Unpin for Simulator<B>
impl<B> UnsafeUnpin for Simulator<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more