Refactor SimpleJITTrapSink/FaerieTrapSink into NullTrapSink.

This publishes it for use outside of simpljie/faerie as well.
This commit is contained in:
Dan Gohman
2018-04-17 11:22:11 -07:00
parent 1f43ec09f3
commit 58380f38e8
5 changed files with 18 additions and 20 deletions

View File

@@ -27,7 +27,7 @@ cargo update
echo git commit -a -m "\"Bump version to $version"\"
echo git push
for crate in entity codegen frontend native reader wasm umbrella ; do
for crate in entity codegen frontend native reader wasm module simplejit faerie umbrella ; do
if [ "$crate" == "umbrella" ]; then
dir="cretonne"
else

View File

@@ -123,3 +123,11 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
self.traps.trap(ofs, srcloc, code);
}
}
/// A `TrapSink` implementation that does nothing, which is convenient when
/// compiling code that does not rely on trapping semantics.
pub struct NullTrapSink {}
impl TrapSink for NullTrapSink {
fn trap(&mut self, _offset: CodeOffset, _srcloc: SourceLoc, _code: TrapCode) {}
}

View File

@@ -6,7 +6,7 @@
mod memorysink;
mod relaxation;
pub use self::memorysink::{MemoryCodeSink, RelocSink, TrapSink};
pub use self::memorysink::{MemoryCodeSink, RelocSink, TrapSink, NullTrapSink};
pub use self::relaxation::relax_branches;
pub use regalloc::RegDiversions;

View File

@@ -1,7 +1,7 @@
//! Defines `FaerieBackend`.
use container;
use cretonne_codegen::binemit::{Addend, CodeOffset, Reloc, RelocSink, TrapSink};
use cretonne_codegen::binemit::{Addend, CodeOffset, Reloc, RelocSink, NullTrapSink};
use cretonne_codegen::isa::TargetIsa;
use cretonne_codegen::result::CtonError;
use cretonne_codegen::{self, binemit, ir};
@@ -103,7 +103,9 @@ impl Backend for FaerieBackend {
name,
namespace,
};
let mut trap_sink = FaerieTrapSink {};
// Ignore traps for now. For now, frontends should just avoid generating code
// that traps.
let mut trap_sink = NullTrapSink {};
ctx.emit_to_memory(
code.as_mut_ptr(),
@@ -289,10 +291,3 @@ impl<'a> RelocSink for FaerieRelocSink<'a> {
unimplemented!();
}
}
struct FaerieTrapSink {}
impl TrapSink for FaerieTrapSink {
// Ignore traps for now. For now, frontends should just avoid generating code that traps.
fn trap(&mut self, _offset: CodeOffset, _srcloc: ir::SourceLoc, _code: ir::TrapCode) {}
}

View File

@@ -1,6 +1,6 @@
//! Defines `SimpleJITBackend`.
use cretonne_codegen::binemit::{Addend, CodeOffset, Reloc, RelocSink, TrapSink};
use cretonne_codegen::binemit::{Addend, CodeOffset, Reloc, RelocSink, NullTrapSink};
use cretonne_codegen::isa::TargetIsa;
use cretonne_codegen::result::CtonError;
use cretonne_codegen::{self, ir, settings};
@@ -100,7 +100,9 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
"TODO: handle OOM etc.",
);
let mut reloc_sink = SimpleJITRelocSink::new();
let mut trap_sink = SimpleJITTrapSink {};
// Ignore traps for now. For now, frontends should just avoid generating code
// that traps.
let mut trap_sink = NullTrapSink {};
ctx.emit_to_memory(ptr, &mut reloc_sink, &mut trap_sink, &*self.isa);
Ok(Self::CompiledFunction {
@@ -356,10 +358,3 @@ impl RelocSink for SimpleJITRelocSink {
unimplemented!();
}
}
struct SimpleJITTrapSink {}
impl TrapSink for SimpleJITTrapSink {
// Ignore traps for now. For now, frontends should just avoid generating code that traps.
fn trap(&mut self, _offset: CodeOffset, _srcloc: ir::SourceLoc, _code: ir::TrapCode) {}
}