1pub mod trace_entry {
2 use serde::{Deserialize, Serialize};
3
4 use crate::{
5 stdlib::prelude::*,
6 types::relocatable::Relocatable,
7 vm::errors::{memory_errors::MemoryError, trace_errors::TraceError},
8 };
9
10 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Clone)]
14 pub struct TraceEntry {
15 pub pc: Relocatable,
16 pub ap: usize,
17 pub fp: usize,
18 }
19
20 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Clone)]
23 pub struct RelocatedTraceEntry {
24 pub pc: usize,
25 pub ap: usize,
26 pub fp: usize,
27 }
28
29 pub fn relocate_trace_register(
30 value: Relocatable,
31 relocation_table: &[usize],
32 ) -> Result<usize, TraceError> {
33 let segment_index: usize = value.segment_index.try_into().map_err(|_| {
34 TraceError::MemoryError(MemoryError::AddressInTemporarySegment(value.segment_index))
35 })?;
36
37 if relocation_table.len() <= segment_index {
38 return Err(TraceError::NoRelocationFound);
39 }
40 Ok(relocation_table[segment_index] + value.offset)
41 }
42}