midenc_codegen_masm/emulator/
events.rs

1use midenc_hir::FunctionIdent;
2
3use super::{Addr, InstructionPointer};
4use crate::BlockId;
5
6/// A control-flow event that occurred as a side-effect of
7/// advancing the instruction pointer.
8#[derive(Debug, Copy, Clone, PartialEq, Eq)]
9pub enum ControlEffect {
10    /// No control effects occurred
11    None,
12    /// We jumped to a nested block
13    Enter,
14    /// We jumped to a parent block
15    Exit,
16    /// We jumped back to the start of a while loop
17    Loopback,
18    /// We started the `n`th iteration of a repeat block
19    Repeat(u16),
20}
21
22#[derive(Debug, Copy, Clone, PartialEq, Eq)]
23pub enum BreakpointEvent {
24    /// Breakpoint was hit because we always break on each step
25    Step,
26    /// Breakpoint was hit because we are stepping out of the current function
27    StepOut,
28    /// Breakpoint for a specific clock cycle was reached
29    ReachedCycle(usize),
30    /// Breakpoint for a specific instruction pointer value was reached
31    Reached(InstructionPointer),
32    /// Breakpoint for a loop was hit
33    Loop(BlockId),
34    /// Breakpoint for the given function was hit
35    Called(FunctionIdent),
36    /// The given watchpoint was hit as a breakpoint
37    Watch(super::Watchpoint),
38}
39
40#[derive(Debug, Copy, Clone)]
41pub enum EmulatorEvent {
42    /// The start of a new cycle has begun
43    CycleStart(usize),
44    /// The specified function was called and the emulator is at the first instruction in its body
45    EnterFunction(FunctionIdent),
46    /// The emulator has returned from the specified function, and the emulator is at the first
47    /// instruction following it in the caller, or if there are no more instructions in the caller,
48    /// waiting to return from the caller function on the next resumption.
49    ExitFunction(FunctionIdent),
50    /// The emulator has entered a loop, whose body is the specified block.
51    ///
52    /// The emulator is at the first instruction in that block.
53    EnterLoop(BlockId),
54    /// The emulator has exited a loop, whose body is the specified block, and is at the first
55    /// instruction following it in the enclosing block. If there are no more instructions after
56    /// the loop, the emulator will return from the enclosing function on the next resumption.
57    ExitLoop(BlockId),
58    /// Control has transferred to `block`
59    ///
60    /// This event is only used when the control flow instruction was not a loop instruction
61    Jump(BlockId),
62    /// The emulator just performed a store to `addr` of `size` bytes
63    MemoryWrite { addr: Addr, size: u32 },
64    /// The emulator has reached a breakpoint
65    Breakpoint(BreakpointEvent),
66    /// The emulator has suspended, and can be resumed at will
67    Suspended,
68    /// The emulator has reached the end of the program and has stopped executing
69    Stopped,
70}