midenc_hir/asm/
events.rs

1//! This module contains the set of compiler-emitted event codes, and their explanations
2use core::num::NonZeroU32;
3
4/// This event is emitted via `trace`, and indicates that a procedure call frame is entered
5///
6/// The mnemonic here is F = frame, 0 = open
7pub const TRACE_FRAME_START: u32 = 0xf0;
8
9/// This event is emitted via `trace`, and indicates that a procedure call frame is exited
10///
11/// The mnemonic here is F = frame, C = close
12pub const TRACE_FRAME_END: u32 = 0xfc;
13
14/// A typed wrapper around the raw trace events known to the compiler
15#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
16#[repr(u32)]
17pub enum TraceEvent {
18    FrameStart,
19    FrameEnd,
20    AssertionFailed(Option<NonZeroU32>),
21    Unknown(u32),
22}
23impl TraceEvent {
24    #[inline(always)]
25    pub fn is_frame_start(&self) -> bool {
26        matches!(self, Self::FrameStart)
27    }
28
29    #[inline(always)]
30    pub fn is_frame_end(&self) -> bool {
31        matches!(self, Self::FrameEnd)
32    }
33}
34impl From<u32> for TraceEvent {
35    fn from(raw: u32) -> Self {
36        match raw {
37            TRACE_FRAME_START => Self::FrameStart,
38            TRACE_FRAME_END => Self::FrameEnd,
39            _ => Self::Unknown(raw),
40        }
41    }
42}
43impl From<TraceEvent> for u32 {
44    fn from(event: TraceEvent) -> Self {
45        match event {
46            TraceEvent::FrameStart => TRACE_FRAME_START,
47            TraceEvent::FrameEnd => TRACE_FRAME_END,
48            TraceEvent::AssertionFailed(None) => 0,
49            TraceEvent::AssertionFailed(Some(code)) => code.get(),
50            TraceEvent::Unknown(code) => code,
51        }
52    }
53}