[cranelift] Rejigger the compile API (#4540)
* Move `emit_to_memory` to `MachCompileResult` This small refactoring makes it clearer to me that emitting to memory doesn't require anything else from the compilation `Context`. While it's a trivial change, it's a small public API change that shouldn't cause too much trouble, and doesn't seem RFC-worthy. Happy to hear different opinions about this, though! * hide the MachCompileResult behind a method * Add a `CompileError` wrapper type that references a `Function` * Rename MachCompileResult to CompiledCode * Additionally remove the last unsafe API in cranelift-codegen
This commit is contained in:
@@ -9,7 +9,7 @@ use super::HashMap;
|
||||
use crate::data_context::DataContext;
|
||||
use cranelift_codegen::entity::{entity_impl, PrimaryMap};
|
||||
use cranelift_codegen::{binemit, MachReloc};
|
||||
use cranelift_codegen::{ir, isa, CodegenError, Context};
|
||||
use cranelift_codegen::{ir, isa, CodegenError, CompileError, Context};
|
||||
use std::borrow::ToOwned;
|
||||
use std::string::String;
|
||||
|
||||
@@ -192,6 +192,12 @@ pub enum ModuleError {
|
||||
Backend(anyhow::Error),
|
||||
}
|
||||
|
||||
impl<'a> From<CompileError<'a>> for ModuleError {
|
||||
fn from(err: CompileError<'a>) -> Self {
|
||||
Self::Compilation(err.inner)
|
||||
}
|
||||
}
|
||||
|
||||
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
|
||||
// of dependencies used by Cranelift.
|
||||
impl std::error::Error for ModuleError {
|
||||
|
||||
Reference in New Issue
Block a user