[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:
@@ -68,17 +68,17 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
||||
let mut mem = vec![];
|
||||
|
||||
// Compile and encode the result to machine code.
|
||||
context
|
||||
let compiled_code = context
|
||||
.compile_and_emit(isa, &mut mem)
|
||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||
let result = context.mach_compile_result.as_ref().unwrap();
|
||||
let code_info = result.code_info();
|
||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&err.func, err.inner)))?;
|
||||
let code_info = compiled_code.code_info();
|
||||
|
||||
if options.print {
|
||||
println!("{}", context.func.display());
|
||||
}
|
||||
|
||||
if options.disasm {
|
||||
let result = context.compiled_code().unwrap();
|
||||
print_all(
|
||||
isa,
|
||||
&mem,
|
||||
|
||||
@@ -257,11 +257,10 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
||||
}
|
||||
(vec![], vec![], vec![])
|
||||
} else {
|
||||
context
|
||||
let compiled_code = context
|
||||
.compile_and_emit(isa, &mut mem)
|
||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||
let result = context.mach_compile_result.as_ref().unwrap();
|
||||
let code_info = result.code_info();
|
||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&err.func, err.inner)))?;
|
||||
let code_info = compiled_code.code_info();
|
||||
|
||||
if options.print_size {
|
||||
println!(
|
||||
@@ -280,9 +279,9 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
||||
saved_size = Some(code_info.total_size);
|
||||
}
|
||||
(
|
||||
result.buffer.relocs().to_vec(),
|
||||
result.buffer.traps().to_vec(),
|
||||
result.buffer.stack_maps().to_vec(),
|
||||
compiled_code.buffer.relocs().to_vec(),
|
||||
compiled_code.buffer.traps().to_vec(),
|
||||
compiled_code.buffer.stack_maps().to_vec(),
|
||||
)
|
||||
};
|
||||
|
||||
@@ -299,14 +298,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
||||
println!("; Exported as \"{}\"", export_name);
|
||||
}
|
||||
let value_ranges = if options.value_ranges {
|
||||
Some(
|
||||
context
|
||||
.mach_compile_result
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.value_labels_ranges
|
||||
.clone(),
|
||||
)
|
||||
Some(context.compiled_code().unwrap().value_labels_ranges.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user