openvm_instructions/
exe.rs
1use std::collections::BTreeMap;
2
3use openvm_stark_backend::p3_field::Field;
4use serde::{Deserialize, Serialize};
5
6use crate::program::Program;
7
8pub type MemoryImage<F> = BTreeMap<(u32, u32), F>;
10pub type FnBounds = BTreeMap<u32, FnBound>;
12
13#[derive(Clone, Debug, Default, Serialize, Deserialize)]
15#[serde(bound(
16 serialize = "F: Serialize",
17 deserialize = "F: std::cmp::Ord + Deserialize<'de>"
18))]
19pub struct VmExe<F> {
20 pub program: Program<F>,
22 pub pc_start: u32,
24 pub init_memory: MemoryImage<F>,
26 pub fn_bounds: FnBounds,
28}
29
30impl<F> VmExe<F> {
31 pub fn new(program: Program<F>) -> Self {
32 Self {
33 program,
34 pc_start: 0,
35 init_memory: BTreeMap::new(),
36 fn_bounds: Default::default(),
37 }
38 }
39 pub fn with_pc_start(mut self, pc_start: u32) -> Self {
40 self.pc_start = pc_start;
41 self
42 }
43 pub fn with_init_memory(mut self, init_memory: MemoryImage<F>) -> Self {
44 self.init_memory = init_memory;
45 self
46 }
47}
48
49impl<F: Field> From<Program<F>> for VmExe<F> {
50 fn from(program: Program<F>) -> Self {
51 Self::new(program)
52 }
53}
54
55#[derive(Debug, Default, Clone, Serialize, Deserialize)]
56pub struct FnBound {
57 pub start: u32,
58 pub end: u32,
59 pub name: String,
60}