openvm_circuit/arch/execution_mode/
pure.rs1use crate::{
2 arch::{execution_mode::ExecutionCtxTrait, VmExecState},
3 system::memory::online::GuestMemory,
4};
5
6#[repr(C)]
7pub struct ExecutionCtx {
8 pub instret_left: u64,
9}
10
11impl ExecutionCtx {
12 pub fn new(instret_left: Option<u64>) -> Self {
13 ExecutionCtx {
14 instret_left: if let Some(end) = instret_left {
15 end
16 } else {
17 u64::MAX
18 },
19 }
20 }
21}
22
23impl ExecutionCtxTrait for ExecutionCtx {
24 #[inline(always)]
25 fn on_memory_operation(&mut self, _address_space: u32, _ptr: u32, _size: u32) {}
26
27 #[inline(always)]
28 fn should_suspend<F>(exec_state: &mut VmExecState<F, GuestMemory, Self>) -> bool {
29 if exec_state.ctx.instret_left == 0 {
32 true
33 } else {
34 exec_state.ctx.instret_left -= 1;
35 false
36 }
37 }
38}