Merge pull request #3680 from bjorn3/remove_code_sink

Remove the CodeSink interface in favor of MachBufferFinalized
This commit is contained in:
Chris Fallin
2022-01-12 10:47:23 -08:00
committed by GitHub
30 changed files with 342 additions and 899 deletions

View File

@@ -1,6 +1,5 @@
//! Provides functionality for compiling and running CLIF IR for `run` tests.
use core::mem;
use cranelift_codegen::binemit::{NullRelocSink, NullStackMapSink, NullTrapSink};
use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::{condcodes::IntCC, Function, InstBuilder, Signature};
use cranelift_codegen::isa::TargetIsa;
@@ -241,14 +240,11 @@ fn compile(function: Function, isa: &dyn TargetIsa) -> Result<Mmap, CompilationE
context.func = function;
// Compile and encode the result to machine code.
let relocs = &mut NullRelocSink {};
let traps = &mut NullTrapSink {};
let stack_maps = &mut NullStackMapSink {};
let code_info = context.compile(isa)?;
let mut code_page = MmapMut::map_anon(code_info.total_size as usize)?;
unsafe {
context.emit_to_memory(code_page.as_mut_ptr(), relocs, traps, stack_maps);
context.emit_to_memory(code_page.as_mut_ptr());
};
let code_page = code_page.make_exec()?;

View File

@@ -4,7 +4,7 @@
use crate::subtest::{run_filecheck, Context, SubTest};
use anyhow::{bail, Result};
use cranelift_codegen::binemit::{self, CodeInfo};
use cranelift_codegen::binemit::CodeInfo;
use cranelift_codegen::ir;
use cranelift_reader::{TestCommand, TestOption};
use log::info;
@@ -75,44 +75,6 @@ impl SubTest for TestCompile {
}
}
/// Code sink that simply counts bytes.
struct SizeSink {
offset: binemit::CodeOffset,
}
impl binemit::CodeSink for SizeSink {
fn offset(&self) -> binemit::CodeOffset {
self.offset
}
fn put1(&mut self, _: u8) {
self.offset += 1;
}
fn put2(&mut self, _: u16) {
self.offset += 2;
}
fn put4(&mut self, _: u32) {
self.offset += 4;
}
fn put8(&mut self, _: u64) {
self.offset += 8;
}
fn reloc_external(
&mut self,
_srcloc: ir::SourceLoc,
_reloc: binemit::Reloc,
_name: &ir::ExternalName,
_addend: binemit::Addend,
) {
}
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
fn end_codegen(&mut self) {}
}
fn check_precise_output(text: &str, context: &Context) -> Result<()> {
let actual = text.lines().collect::<Vec<_>>();