Skip to content

Commit

Permalink
add more cfg(unwind)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Oct 9, 2020
1 parent c8784c7 commit aa4e79d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/aarch64/inst/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl UnwindInfoGenerator<Inst> for AArch64UnwindInfo {
_kind: UnwindInfoKind,
_insts: &[Inst],
_insts_layout: &[CodeOffset],
_len: CodeOffset,
_prologue_epilogue: &(u32, u32, Box<[(u32, u32)]>),
) -> CodegenResult<Option<UnwindInfo>> {
// TODO
Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl MachBackend for AArch64Backend {
buffer,
frame_size,
disasm,
#[cfg(feature = "unwind")]
unwind_info: None,
})
}
Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/arm32/inst/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl UnwindInfoGenerator<Inst> for Arm32UnwindInfo {
_kind: UnwindInfoKind,
_insts: &[Inst],
_insts_layout: &[CodeOffset],
_len: CodeOffset,
_prologue_epilogue: &(u32, u32, Box<[(u32, u32)]>),
) -> CodegenResult<Option<UnwindInfo>> {
// TODO
Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/arm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl MachBackend for Arm32Backend {
buffer,
frame_size,
disasm,
#[cfg(feature = "unwind")]
unwind_info: None,
})
}
Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/x64/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2708,6 +2708,7 @@ impl MachInstEmitInfo for EmitInfo {
impl MachInstEmit for Inst {
type State = EmitState;
type Info = EmitInfo;
#[cfg(feature = "unwind")]
type UnwindInfo = unwind::X64UnwindInfo;

fn emit(&self, sink: &mut MachBuffer<Inst>, info: &Self::Info, state: &mut Self::State) {
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/isa/x64/inst/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl UnwindInfoGenerator<Inst> for X64UnwindInfo {
kind: UnwindInfoKind,
insts: &[Inst],
insts_layout: &[CodeOffset],
len: CodeOffset,
prologue_epilogue: &(u32, u32, Box<[(u32, u32)]>),
) -> CodegenResult<Option<UnwindInfo>> {
// Assumption: RBP is being used as the frame pointer for both calling conventions
Expand All @@ -24,6 +25,7 @@ impl UnwindInfoGenerator<Inst> for X64UnwindInfo {
UnwindInfoKind::SystemV => systemv::create_unwind_info(
insts,
insts_layout,
len,
prologue_epilogue,
Some(regs::rbp()),
)?
Expand Down
4 changes: 1 addition & 3 deletions cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ impl InstructionBuilder {
pub(crate) fn create_unwind_info(
insts: &[Inst],
insts_layout: &[u32],
len: u32,
prologue_epilogue: &(u32, u32, Box<[(u32, u32)]>),
frame_register: Option<Reg>,
) -> CodegenResult<Option<UnwindInfo>> {
let len = *insts_layout.last().unwrap();
assert!(len > 0);

let mut builder = InstructionBuilder::new(frame_register);

let prologue_start = prologue_epilogue.0 as usize;
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/isa/x64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl MachBackend for X64Backend {
let buffer = vcode.emit();
let buffer = buffer.finish();
let frame_size = vcode.frame_size();
#[cfg(feature = "unwind")]
let unwind_info = vcode.unwind_info()?;

let disasm = if want_disasm {
Expand All @@ -71,6 +72,7 @@ impl MachBackend for X64Backend {
buffer,
frame_size,
disasm,
#[cfg(feature = "unwind")]
unwind_info,
})
}
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/machinst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
use crate::binemit::{CodeInfo, CodeOffset, StackMap};
use crate::ir::condcodes::IntCC;
use crate::ir::{Function, Type};
#[cfg(feature = "unwind")]
use crate::isa::unwind;
use crate::result::CodegenResult;
use crate::settings::Flags;
Expand Down Expand Up @@ -391,6 +392,7 @@ pub trait UnwindInfoGenerator<I: MachInstEmit> {
kind: UnwindInfoKind,
insts: &[I],
insts_layout: &[CodeOffset],
len: CodeOffset,
prologue_epilogue: &(u32, u32, Box<[(u32, u32)]>),
) -> CodegenResult<Option<unwind::UnwindInfo>>;
}
19 changes: 9 additions & 10 deletions cranelift/codegen/src/machinst/vcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
//! backend pipeline.

use crate::ir::{self, types, SourceLoc};
#[cfg(feature = "unwind")]
use crate::isa::unwind;
use crate::machinst::*;
use crate::result::CodegenResult;
use crate::settings;
use crate::timing;

Expand Down Expand Up @@ -110,7 +107,7 @@ pub struct VCode<I: VCodeInst> {
prologue_epilogue_ranges: Option<(InsnIndex, InsnIndex, Box<[(InsnIndex, InsnIndex)]>)>,

/// Instruction end offsets
insts_layout: RefCell<Vec<u32>>,
insts_layout: RefCell<(Vec<u32>, u32)>,
}

/// A builder for a VCode function body. This builder is designed for the
Expand Down Expand Up @@ -303,7 +300,7 @@ impl<I: VCodeInst> VCode<I> {
safepoint_insns: vec![],
safepoint_slots: vec![],
prologue_epilogue_ranges: None,
insts_layout: RefCell::new(vec![]),
insts_layout: RefCell::new((vec![], 0)),
}
}

Expand Down Expand Up @@ -535,20 +532,22 @@ impl<I: VCodeInst> VCode<I> {
}
}

self.insts_layout
.borrow_mut()
.extend(insts_layout.into_iter());
*self.insts_layout.borrow_mut() = (insts_layout, buffer.cur_offset());

buffer
}

/// Generates unwind info.
#[cfg(feature = "unwind")]
pub fn unwind_info(&self) -> CodegenResult<Option<unwind::UnwindInfo>> {
pub fn unwind_info(
&self,
) -> crate::result::CodegenResult<Option<crate::isa::unwind::UnwindInfo>> {
let layout = &self.insts_layout.borrow();
I::UnwindInfo::create_unwind_info(
self.abi.unwind_info_kind(),
&self.insts,
&self.insts_layout.borrow(),
&layout.0,
layout.1,
self.prologue_epilogue_ranges.as_ref().unwrap(),
)
}
Expand Down

0 comments on commit aa4e79d

Please sign in to comment.