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