miden_core/operations/decorators/
debug.rs

1use core::fmt;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6// DEBUG OPTIONS
7// ================================================================================================
8
9/// Options of the `Debug` decorator.
10///
11/// These options define the debug info which gets printed out when the Debug decorator is
12/// executed.
13#[derive(Copy, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15#[cfg_attr(all(feature = "arbitrary", test), miden_test_serde_macros::serde_test)]
16pub enum DebugOptions {
17    /// Print out the entire contents of the stack for the current execution context.
18    StackAll,
19    /// Prints out the top n items of the stack for the current context.
20    StackTop(u8),
21    /// Prints out the entire contents of RAM.
22    MemAll,
23    /// Prints out the contents of memory stored in the provided interval. Interval boundaries are
24    /// both inclusive.
25    ///
26    /// First parameter specifies the interval starting address, second -- the ending address.
27    MemInterval(u32, u32),
28    /// Prints out locals stored in the provided interval of the currently executing procedure.
29    /// Interval boundaries are both inclusive.
30    ///
31    /// First parameter specifies the starting address, second -- the ending address, and the third
32    /// specifies the overall number of locals.
33    LocalInterval(u16, u16, u16),
34    /// Prints out the top n items of the advice stack for the current context.
35    ///
36    /// If `n = 0`, the entire stack is printed.
37    AdvStackTop(u16),
38}
39
40impl crate::prettier::PrettyPrint for DebugOptions {
41    fn render(&self) -> crate::prettier::Document {
42        crate::prettier::display(self)
43    }
44}
45
46impl fmt::Display for DebugOptions {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            Self::StackAll => write!(f, "stack"),
50            Self::StackTop(n) => write!(f, "stack.{n}"),
51            Self::MemAll => write!(f, "mem"),
52            Self::MemInterval(n, m) => write!(f, "mem.{n}.{m}"),
53            Self::LocalInterval(start, end, _) => {
54                write!(f, "local.{start}.{end}")
55            },
56            Self::AdvStackTop(n) => write!(f, "adv_stack.{n}"),
57        }
58    }
59}