cranelift: refactor unwind logic to accommodate multiple backends (#2357)
* Make cranelift_codegen::isa::unwind::input public * Move UnwindCode's common offset field out of the structure * Make MachCompileResult::unwind_info more generic * Record initial stack pointer offset
This commit is contained in:
@@ -21,51 +21,68 @@ pub enum UnwindInfo {
|
||||
SystemV(systemv::UnwindInfo),
|
||||
}
|
||||
|
||||
pub(crate) mod input {
|
||||
/// Intermediate representation for the unwind information
|
||||
/// generated by a backend.
|
||||
pub mod input {
|
||||
use crate::binemit::CodeOffset;
|
||||
use alloc::vec::Vec;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Elementary operation in the unwind operations.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub(crate) enum UnwindCode<Reg> {
|
||||
pub enum UnwindCode<Reg> {
|
||||
/// Defines that a register is saved at the specified offset.
|
||||
SaveRegister {
|
||||
offset: CodeOffset,
|
||||
/// The saved register.
|
||||
reg: Reg,
|
||||
/// The specified offset relative to the stack pointer.
|
||||
stack_offset: u32,
|
||||
},
|
||||
/// Defines that a register is as defined before call.
|
||||
RestoreRegister {
|
||||
offset: CodeOffset,
|
||||
/// The restored register.
|
||||
reg: Reg,
|
||||
},
|
||||
/// The stack pointer was adjusted to allocate the stack.
|
||||
StackAlloc {
|
||||
offset: CodeOffset,
|
||||
/// Size to allocate.
|
||||
size: u32,
|
||||
},
|
||||
/// The stack pointer was adjusted to free the stack.
|
||||
StackDealloc {
|
||||
offset: CodeOffset,
|
||||
/// Size to deallocate.
|
||||
size: u32,
|
||||
},
|
||||
/// The alternative register was assigned as frame pointer base.
|
||||
SetFramePointer {
|
||||
offset: CodeOffset,
|
||||
/// The specified register.
|
||||
reg: Reg,
|
||||
},
|
||||
RememberState {
|
||||
offset: CodeOffset,
|
||||
},
|
||||
RestoreState {
|
||||
offset: CodeOffset,
|
||||
},
|
||||
/// Restores a frame pointer base to default register.
|
||||
RestoreFramePointer,
|
||||
/// Saves the state.
|
||||
RememberState,
|
||||
/// Restores the state.
|
||||
RestoreState,
|
||||
}
|
||||
|
||||
/// Unwind information as generated by a backend.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct UnwindInfo<Reg> {
|
||||
pub(crate) prologue_size: CodeOffset,
|
||||
pub(crate) prologue_unwind_codes: Vec<UnwindCode<Reg>>,
|
||||
pub(crate) epilogues_unwind_codes: Vec<Vec<UnwindCode<Reg>>>,
|
||||
pub(crate) function_size: CodeOffset,
|
||||
pub(crate) word_size: u8,
|
||||
/// Size of the prologue.
|
||||
pub prologue_size: CodeOffset,
|
||||
/// Unwind codes for prologue.
|
||||
pub prologue_unwind_codes: Vec<(CodeOffset, UnwindCode<Reg>)>,
|
||||
/// Unwind codes for epilogues.
|
||||
pub epilogues_unwind_codes: Vec<Vec<(CodeOffset, UnwindCode<Reg>)>>,
|
||||
/// Entire function size.
|
||||
pub function_size: CodeOffset,
|
||||
/// Platform word size in bytes.
|
||||
pub word_size: u8,
|
||||
/// Initial stack pointer offset.
|
||||
pub initial_sp_offset: u8,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user