Add TargetIsa::map_dwarf_register; fixes #1471
This exposes the functionality of `fde::map_reg` on the `TargetIsa` trait, avoiding compilation errors on architectures where register mapping is not yet supported. The change is conditially compiled under the `unwind` feature.
This commit is contained in:
14
cranelift/codegen/src/isa/fde.rs
Normal file
14
cranelift/codegen/src/isa/fde.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
//! Support for FDE data generation.
|
||||
use thiserror::Error;
|
||||
|
||||
/// Enumerate the errors possible in mapping Cranelift registers to their DWARF equivalent.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum RegisterMappingError {
|
||||
#[error("unable to find bank for register info")]
|
||||
MissingBank,
|
||||
#[error("register mapping is currently only implemented for x86_64")]
|
||||
UnsupportedArchitecture,
|
||||
#[error("unsupported register bank: {0}")]
|
||||
UnsupportedRegisterBank(&'static str),
|
||||
}
|
||||
@@ -56,6 +56,8 @@ use crate::binemit;
|
||||
use crate::flowgraph;
|
||||
use crate::ir;
|
||||
use crate::isa::enc_tables::Encodings;
|
||||
#[cfg(feature = "unwind")]
|
||||
use crate::isa::fde::RegisterMappingError;
|
||||
use crate::regalloc;
|
||||
use crate::result::CodegenResult;
|
||||
use crate::settings;
|
||||
@@ -74,11 +76,8 @@ mod riscv;
|
||||
#[cfg(feature = "x86")]
|
||||
mod x86;
|
||||
|
||||
#[cfg(all(feature = "x86", feature = "unwind"))]
|
||||
/// Expose the register-mapping functionality necessary for exception handling, debug, etc.
|
||||
pub mod fde {
|
||||
pub use super::x86::map_reg;
|
||||
}
|
||||
#[cfg(feature = "unwind")]
|
||||
pub mod fde;
|
||||
|
||||
#[cfg(feature = "arm32")]
|
||||
mod arm32;
|
||||
@@ -260,6 +259,12 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
|
||||
/// Get a data structure describing the registers in this ISA.
|
||||
fn register_info(&self) -> RegInfo;
|
||||
|
||||
#[cfg(feature = "unwind")]
|
||||
/// Map a Cranelift register to its corresponding DWARF register.
|
||||
fn map_dwarf_register(&self, _: RegUnit) -> Result<u16, RegisterMappingError> {
|
||||
Err(RegisterMappingError::UnsupportedArchitecture)
|
||||
}
|
||||
|
||||
/// Returns an iterator over legal encodings for the instruction.
|
||||
fn legal_encodings<'a>(
|
||||
&'a self,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use crate::binemit::{FrameUnwindOffset, FrameUnwindSink, Reloc};
|
||||
use crate::ir::{FrameLayoutChange, Function};
|
||||
use crate::isa::fde::RegisterMappingError;
|
||||
use crate::isa::{CallConv, RegUnit, TargetIsa};
|
||||
use alloc::vec::Vec;
|
||||
use core::convert::TryInto;
|
||||
@@ -10,7 +11,6 @@ use gimli::write::{
|
||||
FrameDescriptionEntry, FrameTable, Result, Writer,
|
||||
};
|
||||
use gimli::{Encoding, Format, LittleEndian, Register, X86_64};
|
||||
use thiserror::Error;
|
||||
|
||||
pub type FDERelocEntry = (FrameUnwindOffset, Reloc);
|
||||
|
||||
@@ -137,16 +137,6 @@ pub fn map_reg(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum RegisterMappingError {
|
||||
#[error("unable to find bank for register info")]
|
||||
MissingBank,
|
||||
#[error("register mapping is currently only implemented for x86_64")]
|
||||
UnsupportedArchitecture,
|
||||
#[error("unsupported register bank: {0}")]
|
||||
UnsupportedRegisterBank(&'static str),
|
||||
}
|
||||
|
||||
fn to_cfi(
|
||||
isa: &dyn TargetIsa,
|
||||
change: &FrameLayoutChange,
|
||||
|
||||
@@ -22,6 +22,8 @@ use crate::binemit::{FrameUnwindKind, FrameUnwindSink};
|
||||
use crate::ir;
|
||||
use crate::isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings};
|
||||
use crate::isa::Builder as IsaBuilder;
|
||||
#[cfg(feature = "unwind")]
|
||||
use crate::isa::{fde::RegisterMappingError, RegUnit};
|
||||
use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use crate::result::CodegenResult;
|
||||
@@ -91,6 +93,11 @@ impl TargetIsa for Isa {
|
||||
registers::INFO.clone()
|
||||
}
|
||||
|
||||
#[cfg(feature = "unwind")]
|
||||
fn map_dwarf_register(&self, reg: RegUnit) -> Result<u16, RegisterMappingError> {
|
||||
map_reg(self, reg).map(|r| r.0)
|
||||
}
|
||||
|
||||
fn encoding_info(&self) -> EncInfo {
|
||||
enc_tables::INFO.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user