Skip to main content

miden_core/operations/decorators/
mod.rs

1use alloc::{string::ToString, vec::Vec};
2use core::fmt;
3
4use miden_crypto::hash::blake::Blake3_256;
5use num_traits::ToBytes;
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8
9mod assembly_op;
10pub use assembly_op::AssemblyOp;
11
12mod debug;
13pub use debug::DebugOptions;
14
15mod debug_var;
16pub use debug_var::{DebugVarInfo, DebugVarLocation};
17
18use crate::mast::{DecoratedOpLink, DecoratorFingerprint};
19
20// DECORATORS
21// ================================================================================================
22
23/// A set of decorators which can be executed by the VM.
24///
25/// Executing a decorator does not affect the state of the main VM components such as operand stack
26/// and memory.
27///
28/// Executing decorators does not advance the VM clock. As such, many decorators can be executed in
29/// a single VM cycle.
30#[derive(Clone, Debug, Eq, PartialEq)]
31#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
32#[cfg_attr(all(feature = "arbitrary", test), miden_test_serde_macros::serde_test)]
33pub enum Decorator {
34    /// Prints out information about the state of the VM based on the specified options. This
35    /// decorator is executed only in debug mode.
36    Debug(DebugOptions),
37    /// Emits a trace to the host.
38    Trace(u32),
39}
40
41impl Decorator {
42    pub fn fingerprint(&self) -> DecoratorFingerprint {
43        match self {
44            Self::Debug(debug) => Blake3_256::hash(debug.to_string().as_bytes()),
45            Self::Trace(trace) => Blake3_256::hash(&trace.to_le_bytes()),
46        }
47    }
48}
49
50impl crate::prettier::PrettyPrint for Decorator {
51    fn render(&self) -> crate::prettier::Document {
52        crate::prettier::display(self)
53    }
54}
55
56impl fmt::Display for Decorator {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        match self {
59            Self::Debug(options) => write!(f, "debug({options})"),
60            Self::Trace(trace_id) => write!(f, "trace({trace_id})"),
61        }
62    }
63}
64
65/// Vector consisting of a tuple of operation index (within a span block) and decorator at that
66/// index.
67pub type DecoratorList = Vec<DecoratedOpLink>;