Don't return CodeInfo from Context::compile_and_emit
It is already available through ctx.mach_compile_result and rarely needed.
This commit is contained in:
@@ -114,7 +114,7 @@ impl Context {
|
|||||||
relocs: &mut dyn RelocSink,
|
relocs: &mut dyn RelocSink,
|
||||||
traps: &mut dyn TrapSink,
|
traps: &mut dyn TrapSink,
|
||||||
stack_maps: &mut dyn StackMapSink,
|
stack_maps: &mut dyn StackMapSink,
|
||||||
) -> CodegenResult<CodeInfo> {
|
) -> CodegenResult<()> {
|
||||||
let info = self.compile(isa)?;
|
let info = self.compile(isa)?;
|
||||||
let old_len = mem.len();
|
let old_len = mem.len();
|
||||||
mem.resize(old_len + info.total_size as usize, 0);
|
mem.resize(old_len + info.total_size as usize, 0);
|
||||||
@@ -122,7 +122,7 @@ impl Context {
|
|||||||
self.emit_to_memory(mem.as_mut_ptr().add(old_len), relocs, traps, stack_maps)
|
self.emit_to_memory(mem.as_mut_ptr().add(old_len), relocs, traps, stack_maps)
|
||||||
};
|
};
|
||||||
debug_assert!(new_info == info);
|
debug_assert!(new_info == info);
|
||||||
Ok(info)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile the function.
|
/// Compile the function.
|
||||||
|
|||||||
@@ -652,11 +652,6 @@ impl Module for JITModule {
|
|||||||
stack_map_sink: &mut dyn StackMapSink,
|
stack_map_sink: &mut dyn StackMapSink,
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
info!("defining function {}: {}", id, ctx.func.display());
|
info!("defining function {}: {}", id, ctx.func.display());
|
||||||
let CodeInfo {
|
|
||||||
total_size: code_size,
|
|
||||||
..
|
|
||||||
} = ctx.compile(self.isa())?;
|
|
||||||
|
|
||||||
let decl = self.declarations.get_function_decl(id);
|
let decl = self.declarations.get_function_decl(id);
|
||||||
if !decl.linkage.is_definable() {
|
if !decl.linkage.is_definable() {
|
||||||
return Err(ModuleError::InvalidImportDefinition(decl.name.clone()));
|
return Err(ModuleError::InvalidImportDefinition(decl.name.clone()));
|
||||||
@@ -666,6 +661,11 @@ impl Module for JITModule {
|
|||||||
return Err(ModuleError::DuplicateDefinition(decl.name.to_owned()));
|
return Err(ModuleError::DuplicateDefinition(decl.name.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let CodeInfo {
|
||||||
|
total_size: code_size,
|
||||||
|
..
|
||||||
|
} = ctx.compile(self.isa())?;
|
||||||
|
|
||||||
let size = code_size as usize;
|
let size = code_size as usize;
|
||||||
let ptr = self
|
let ptr = self
|
||||||
.memory
|
.memory
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use cranelift_codegen::entity::SecondaryMap;
|
|||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
use cranelift_codegen::{self, ir};
|
use cranelift_codegen::{self, ir};
|
||||||
use cranelift_codegen::{
|
use cranelift_codegen::{
|
||||||
binemit::{Addend, CodeInfo, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
|
binemit::{Addend, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
|
||||||
CodegenError,
|
CodegenError,
|
||||||
};
|
};
|
||||||
use cranelift_module::{
|
use cranelift_module::{
|
||||||
@@ -311,21 +311,16 @@ impl Module for ObjectModule {
|
|||||||
stack_map_sink: &mut dyn StackMapSink,
|
stack_map_sink: &mut dyn StackMapSink,
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
info!("defining function {}: {}", func_id, ctx.func.display());
|
info!("defining function {}: {}", func_id, ctx.func.display());
|
||||||
let CodeInfo {
|
let mut code: Vec<u8> = Vec::new();
|
||||||
total_size: code_size,
|
|
||||||
..
|
|
||||||
} = ctx.compile(self.isa())?;
|
|
||||||
let mut code: Vec<u8> = vec![0; code_size as usize];
|
|
||||||
let mut reloc_sink = ObjectRelocSink::default();
|
let mut reloc_sink = ObjectRelocSink::default();
|
||||||
|
|
||||||
unsafe {
|
ctx.compile_and_emit(
|
||||||
ctx.emit_to_memory(
|
self.isa(),
|
||||||
code.as_mut_ptr(),
|
&mut code,
|
||||||
&mut reloc_sink,
|
&mut reloc_sink,
|
||||||
trap_sink,
|
trap_sink,
|
||||||
stack_map_sink,
|
stack_map_sink,
|
||||||
)
|
)?;
|
||||||
};
|
|
||||||
|
|
||||||
self.define_function_bytes(func_id, &code, &reloc_sink.relocs)
|
self.define_function_bytes(func_id, &code, &reloc_sink.relocs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,10 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
let mut mem = vec![];
|
let mut mem = vec![];
|
||||||
|
|
||||||
// Compile and encode the result to machine code.
|
// Compile and encode the result to machine code.
|
||||||
let code_info = context
|
context
|
||||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
||||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||||
|
let code_info = context.mach_compile_result.as_ref().unwrap().code_info();
|
||||||
|
|
||||||
if options.print {
|
if options.print {
|
||||||
println!("{}", context.func.display());
|
println!("{}", context.func.display());
|
||||||
|
|||||||
@@ -266,9 +266,10 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
anyhow::bail!("{}", pretty_verifier_error(&context.func, None, errors));
|
anyhow::bail!("{}", pretty_verifier_error(&context.func, None, errors));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let code_info = context
|
context
|
||||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
||||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||||
|
let code_info = context.mach_compile_result.as_ref().unwrap().code_info();
|
||||||
|
|
||||||
if options.print_size {
|
if options.print_size {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
Reference in New Issue
Block a user