Skip to main content

midenc_codegen_masm/
events.rs

1//! This module contains the set of compiler-emitted event codes, and their explanations
2use miden_core::events::{EventId, EventName};
3
4/// This event indicates that a procedure call frame is entered
5pub const FRAME_START_EVENT: EventName = EventName::new("readonly::miden_debug::frame_start");
6
7/// This event indicates that a procedure call frame is exited
8pub const FRAME_END_EVENT: EventName = EventName::new("readonly::miden_debug::frame_end");
9
10/// This event indicates that a line should be printed.
11///
12/// The bytes representing the string are expected in memory. The executor reads the start address
13/// and length from the operand stack.
14pub const PRINT_LN_EVENT: EventName = EventName::new("readonly::miden_debug::println");
15
16/// A typed wrapper around the raw events known to the compiler
17#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[repr(u32)]
19pub enum Event {
20    FrameStart,
21    FrameEnd,
22    PrintLn,
23    Unknown(EventId),
24}
25impl Event {
26    #[inline(always)]
27    pub fn is_frame_start(&self) -> bool {
28        matches!(self, Self::FrameStart)
29    }
30
31    #[inline(always)]
32    pub fn is_frame_end(&self) -> bool {
33        matches!(self, Self::FrameEnd)
34    }
35
36    pub fn as_event_id(self) -> EventId {
37        match self {
38            Self::FrameStart => FRAME_START_EVENT.to_event_id(),
39            Self::FrameEnd => FRAME_END_EVENT.to_event_id(),
40            Self::PrintLn => PRINT_LN_EVENT.to_event_id(),
41            Self::Unknown(event) => event,
42        }
43    }
44}
45
46impl From<Event> for EventId {
47    fn from(event: Event) -> Self {
48        event.as_event_id()
49    }
50}