Browse Source

Don't return CodeInfo from Context::compile_and_emit

It is already available through ctx.mach_compile_result and rarely
needed.
pull/3639/head
bjorn3 3 years ago
parent
commit
b3aa692a44
  1. 4
      cranelift/codegen/src/context.rs
  2. 10
      cranelift/jit/src/backend.rs
  3. 23
      cranelift/object/src/backend.rs
  4. 3
      cranelift/src/compile.rs
  5. 3
      cranelift/src/wasm.rs

4
cranelift/codegen/src/context.rs

@ -114,7 +114,7 @@ impl Context {
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink,
) -> CodegenResult<CodeInfo> {
) -> CodegenResult<()> {
let info = self.compile(isa)?;
let old_len = mem.len();
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)
};
debug_assert!(new_info == info);
Ok(info)
Ok(())
}
/// Compile the function.

10
cranelift/jit/src/backend.rs

@ -652,11 +652,6 @@ impl Module for JITModule {
stack_map_sink: &mut dyn StackMapSink,
) -> ModuleResult<ModuleCompiledFunction> {
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);
if !decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(decl.name.clone()));
@ -666,6 +661,11 @@ impl Module for JITModule {
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 ptr = self
.memory

23
cranelift/object/src/backend.rs

@ -5,7 +5,7 @@ use cranelift_codegen::entity::SecondaryMap;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::{self, ir};
use cranelift_codegen::{
binemit::{Addend, CodeInfo, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
binemit::{Addend, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
CodegenError,
};
use cranelift_module::{
@ -311,21 +311,16 @@ impl Module for ObjectModule {
stack_map_sink: &mut dyn StackMapSink,
) -> ModuleResult<ModuleCompiledFunction> {
info!("defining function {}: {}", func_id, ctx.func.display());
let CodeInfo {
total_size: code_size,
..
} = ctx.compile(self.isa())?;
let mut code: Vec<u8> = vec![0; code_size as usize];
let mut code: Vec<u8> = Vec::new();
let mut reloc_sink = ObjectRelocSink::default();
unsafe {
ctx.emit_to_memory(
code.as_mut_ptr(),
&mut reloc_sink,
trap_sink,
stack_map_sink,
)
};
ctx.compile_and_emit(
self.isa(),
&mut code,
&mut reloc_sink,
trap_sink,
stack_map_sink,
)?;
self.define_function_bytes(func_id, &code, &reloc_sink.relocs)
}

3
cranelift/src/compile.rs

@ -78,9 +78,10 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
let mut mem = vec![];
// 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)
.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 {
println!("{}", context.func.display());

3
cranelift/src/wasm.rs

@ -266,9 +266,10 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
anyhow::bail!("{}", pretty_verifier_error(&context.func, None, errors));
}
} else {
let code_info = context
context
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
.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 {
println!(

Loading…
Cancel
Save