datex_core/runtime/execution/
memory_dump.rs1use crate::runtime::execution::execution_loop::state::RuntimeExecutionSlots;
2use crate::stdlib::vec::Vec;
3use crate::values::value_container::ValueContainer;
4use core::fmt::Display;
5use itertools::Itertools;
6
7pub struct MemoryDump {
8 pub slots: Vec<(u32, Option<ValueContainer>)>,
9}
10
11#[cfg(feature = "compiler")]
12impl Display for MemoryDump {
13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 for (address, value) in &self.slots {
15 match value {
16 Some(vc) => {
17 let decompiled = crate::decompiler::decompile_value(
18 vc,
19 crate::decompiler::DecompileOptions::colorized(),
20 );
21 writeln!(f, "#{address}: {decompiled}")?
22 }
23 None => writeln!(f, "#{address}: <uninitialized>")?,
24 }
25 }
26 if self.slots.is_empty() {
27 writeln!(f, "<no slots allocated>")?;
28 }
29 Ok(())
30 }
31}
32
33impl RuntimeExecutionSlots {
34 pub fn memory_dump(&self) -> MemoryDump {
36 MemoryDump {
37 slots: self
38 .slots
39 .iter()
40 .map(|(k, v)| (*k, v.clone()))
41 .sorted_by_key(|(k, _)| *k)
42 .collect(),
43 }
44 }
45}