Make get_mach_backend non-optional
This commit is contained in:
@@ -167,8 +167,7 @@ impl Context {
|
|||||||
|
|
||||||
self.remove_constant_phis(isa)?;
|
self.remove_constant_phis(isa)?;
|
||||||
|
|
||||||
// FIXME: make this non optional
|
let backend = isa.get_mach_backend();
|
||||||
let backend = isa.get_mach_backend().expect("only mach backends nowadays");
|
|
||||||
let result = backend.compile_function(&self.func, self.want_disasm)?;
|
let result = backend.compile_function(&self.func, self.want_disasm)?;
|
||||||
let info = result.code_info();
|
let info = result.code_info();
|
||||||
self.mach_compile_result = Some(result);
|
self.mach_compile_result = Some(result);
|
||||||
@@ -243,12 +242,10 @@ impl Context {
|
|||||||
&self,
|
&self,
|
||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
) -> CodegenResult<Option<crate::isa::unwind::UnwindInfo>> {
|
) -> CodegenResult<Option<crate::isa::unwind::UnwindInfo>> {
|
||||||
if let Some(backend) = isa.get_mach_backend() {
|
let backend = isa.get_mach_backend();
|
||||||
let unwind_info_kind = isa.unwind_info_kind();
|
let unwind_info_kind = isa.unwind_info_kind();
|
||||||
let result = self.mach_compile_result.as_ref().unwrap();
|
let result = self.mach_compile_result.as_ref().unwrap();
|
||||||
return backend.emit_unwind_info(result, unwind_info_kind);
|
backend.emit_unwind_info(result, unwind_info_kind)
|
||||||
}
|
|
||||||
isa.create_unwind_info(&self.func)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the verifier on the function.
|
/// Run the verifier on the function.
|
||||||
|
|||||||
@@ -258,10 +258,8 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the new-style MachBackend, if this is an adapter around one.
|
/// Get the new-style MachBackend.
|
||||||
fn get_mach_backend(&self) -> Option<&dyn MachBackend> {
|
fn get_mach_backend(&self) -> &dyn MachBackend;
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Methods implemented for free for target ISA!
|
/// Methods implemented for free for target ISA!
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ impl TargetIsa for TargetIsaAdapter {
|
|||||||
self.backend.isa_flags()
|
self.backend.isa_flags()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_mach_backend(&self) -> Option<&dyn MachBackend> {
|
fn get_mach_backend(&self) -> &dyn MachBackend {
|
||||||
Some(&*self.backend)
|
&*self.backend
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unsigned_add_overflow_condition(&self) -> ir::condcodes::IntCC {
|
fn unsigned_add_overflow_condition(&self) -> ir::condcodes::IntCC {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
use crate::debug::{DwarfSection, DwarfSectionRelocTarget};
|
use crate::debug::{DwarfSection, DwarfSectionRelocTarget};
|
||||||
use crate::{CompiledFunction, Relocation, RelocationTarget};
|
use crate::{CompiledFunction, Relocation, RelocationTarget};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cranelift_codegen::binemit::{Addend, Reloc};
|
use cranelift_codegen::binemit::Reloc;
|
||||||
use cranelift_codegen::ir::LibCall;
|
use cranelift_codegen::ir::LibCall;
|
||||||
use cranelift_codegen::isa::{
|
use cranelift_codegen::isa::{
|
||||||
unwind::{systemv, UnwindInfo},
|
unwind::{systemv, UnwindInfo},
|
||||||
@@ -204,12 +204,9 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
systemv_unwind_info_id: None,
|
systemv_unwind_info_id: None,
|
||||||
systemv_unwind_info: Vec::new(),
|
systemv_unwind_info: Vec::new(),
|
||||||
relocations: Vec::new(),
|
relocations: Vec::new(),
|
||||||
text: match isa.get_mach_backend() {
|
text: isa
|
||||||
Some(backend) => backend.text_section_builder(
|
.get_mach_backend()
|
||||||
(module.functions.len() - module.num_imported_funcs) as u32,
|
.text_section_builder((module.functions.len() - module.num_imported_funcs) as u32),
|
||||||
),
|
|
||||||
None => Box::new(DummyBuilder::default()),
|
|
||||||
},
|
|
||||||
added_unwind_info: false,
|
added_unwind_info: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -627,37 +624,3 @@ impl<'a> ObjectBuilder<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct DummyBuilder {
|
|
||||||
data: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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<u8> {
|
|
||||||
mem::take(&mut self.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user