Skip to main content

cranelift_codegen/isa/x64/inst/
emit_state.rs

1use super::*;
2use cranelift_control::ControlPlane;
3
4/// State carried between emissions of a sequence of instructions.
5#[derive(Default, Clone, Debug)]
6pub struct EmitState {
7    /// Tracks user stack maps for safepoint instructions.
8    pub(crate) stack_maps: StackMapEmitter<Inst>,
9
10    /// Only used during fuzz-testing. Otherwise, it is a zero-sized struct and
11    /// optimized away at compiletime. See [cranelift_control].
12    ctrl_plane: ControlPlane,
13
14    /// A copy of the frame layout, used during the emission of `Inst::ReturnCallKnown` and
15    /// `Inst::ReturnCallUnknown` instructions and exception callsites.
16    pub frame_layout: FrameLayout,
17}
18
19impl MachInstEmitState<Inst> for EmitState {
20    fn new(abi: &Callee<X64ABIMachineSpec>, ctrl_plane: ControlPlane) -> Self {
21        EmitState {
22            stack_maps: StackMapEmitter::default(),
23            ctrl_plane,
24            frame_layout: abi.frame_layout().clone(),
25        }
26    }
27
28    fn stack_map_emitter(&mut self) -> &mut StackMapEmitter<Inst> {
29        &mut self.stack_maps
30    }
31
32    fn ctrl_plane_mut(&mut self) -> &mut ControlPlane {
33        &mut self.ctrl_plane
34    }
35
36    fn take_ctrl_plane(self) -> ControlPlane {
37        self.ctrl_plane
38    }
39
40    fn frame_layout(&self) -> &FrameLayout {
41        &self.frame_layout
42    }
43}