diff --git a/cranelift/codegen/src/context.rs b/cranelift/codegen/src/context.rs index cf0b20e672..d416ef8be2 100644 --- a/cranelift/codegen/src/context.rs +++ b/cranelift/codegen/src/context.rs @@ -167,8 +167,7 @@ impl Context { self.remove_constant_phis(isa)?; - // FIXME: make this non optional - let backend = isa.get_mach_backend().expect("only mach backends nowadays"); + let backend = isa.get_mach_backend(); let result = backend.compile_function(&self.func, self.want_disasm)?; let info = result.code_info(); self.mach_compile_result = Some(result); @@ -243,12 +242,10 @@ impl Context { &self, isa: &dyn TargetIsa, ) -> CodegenResult> { - if let Some(backend) = isa.get_mach_backend() { - let unwind_info_kind = isa.unwind_info_kind(); - let result = self.mach_compile_result.as_ref().unwrap(); - return backend.emit_unwind_info(result, unwind_info_kind); - } - isa.create_unwind_info(&self.func) + let backend = isa.get_mach_backend(); + let unwind_info_kind = isa.unwind_info_kind(); + let result = self.mach_compile_result.as_ref().unwrap(); + backend.emit_unwind_info(result, unwind_info_kind) } /// Run the verifier on the function. diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index b1ff090498..f43e9650a8 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -258,10 +258,8 @@ pub trait TargetIsa: fmt::Display + Send + Sync { None } - /// Get the new-style MachBackend, if this is an adapter around one. - fn get_mach_backend(&self) -> Option<&dyn MachBackend> { - None - } + /// Get the new-style MachBackend. + fn get_mach_backend(&self) -> &dyn MachBackend; } /// Methods implemented for free for target ISA! diff --git a/cranelift/codegen/src/machinst/adapter.rs b/cranelift/codegen/src/machinst/adapter.rs index ee797c466a..c6c6c0a02f 100644 --- a/cranelift/codegen/src/machinst/adapter.rs +++ b/cranelift/codegen/src/machinst/adapter.rs @@ -55,8 +55,8 @@ impl TargetIsa for TargetIsaAdapter { self.backend.isa_flags() } - fn get_mach_backend(&self) -> Option<&dyn MachBackend> { - Some(&*self.backend) + fn get_mach_backend(&self) -> &dyn MachBackend { + &*self.backend } fn unsigned_add_overflow_condition(&self) -> ir::condcodes::IntCC { diff --git a/crates/cranelift/src/obj.rs b/crates/cranelift/src/obj.rs index 08048e5e86..763ae1afcd 100644 --- a/crates/cranelift/src/obj.rs +++ b/crates/cranelift/src/obj.rs @@ -16,7 +16,7 @@ use crate::debug::{DwarfSection, DwarfSectionRelocTarget}; use crate::{CompiledFunction, Relocation, RelocationTarget}; use anyhow::Result; -use cranelift_codegen::binemit::{Addend, Reloc}; +use cranelift_codegen::binemit::Reloc; use cranelift_codegen::ir::LibCall; use cranelift_codegen::isa::{ unwind::{systemv, UnwindInfo}, @@ -204,12 +204,9 @@ impl<'a> ObjectBuilder<'a> { systemv_unwind_info_id: None, systemv_unwind_info: Vec::new(), relocations: Vec::new(), - text: match isa.get_mach_backend() { - Some(backend) => backend.text_section_builder( - (module.functions.len() - module.num_imported_funcs) as u32, - ), - None => Box::new(DummyBuilder::default()), - }, + text: isa + .get_mach_backend() + .text_section_builder((module.functions.len() - module.num_imported_funcs) as u32), added_unwind_info: false, } } @@ -627,37 +624,3 @@ impl<'a> ObjectBuilder<'a> { } } } - -#[derive(Default)] -struct DummyBuilder { - data: Vec, -} - -impl TextSectionBuilder for DummyBuilder { - fn append(&mut self, _named: bool, func: &[u8], align: u32) -> u64 { - while self.data.len() % align as usize != 0 { - self.data.push(0); - } - let pos = self.data.len() as u64; - self.data.extend_from_slice(func); - pos - } - - fn resolve_reloc( - &mut self, - _offset: u64, - _reloc: Reloc, - _addend: Addend, - _target: u32, - ) -> bool { - false - } - - fn force_veneers(&mut self) { - // not implemented - } - - fn finish(&mut self) -> Vec { - mem::take(&mut self.data) - } -}