Remove sink arguments from compile_and_emit

The data can be accessed after the fact using context.mach_compile_result
This commit is contained in:
bjorn3
2022-01-11 18:17:29 +01:00
parent 55d722db05
commit b803514d55
13 changed files with 155 additions and 138 deletions

View File

@@ -3,10 +3,11 @@
use crate::disasm::{print_all, PrintRelocs, PrintStackMaps, PrintTraps};
use crate::utils::{parse_sets_and_triple, read_to_string};
use anyhow::{Context as _, Result};
use cranelift_codegen::binemit::{RelocSink, StackMapSink, TrapSink};
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::settings::FlagsOrIsa;
use cranelift_codegen::timing;
use cranelift_codegen::Context;
use cranelift_codegen::{timing, MachReloc, MachStackMap, MachTrap};
use cranelift_reader::{parse_test, ParseOptions};
use std::path::Path;
use std::path::PathBuf;
@@ -79,9 +80,36 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
// Compile and encode the result to machine code.
context
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
.compile_and_emit(isa, &mut mem)
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
let code_info = context.mach_compile_result.as_ref().unwrap().code_info();
let result = context.mach_compile_result.as_ref().unwrap();
let code_info = result.code_info();
for &MachReloc {
offset,
srcloc,
kind,
ref name,
addend,
} in result.buffer.relocs()
{
relocs.reloc_external(offset, srcloc, kind, name, addend);
}
for &MachTrap {
offset,
srcloc,
code,
} in result.buffer.traps()
{
traps.trap(offset, srcloc, code);
}
for &MachStackMap {
offset_end,
ref stack_map,
..
} in result.buffer.stack_maps()
{
stack_maps.add_stack_map(offset_end, stack_map.clone());
}
if options.print {
println!("{}", context.func.display());