Add reference types R32 and R64

-Add resumable_trap, safepoint, isnull, and null instructions
-Add Stackmap struct and StackmapSink trait

Co-authored-by: Mir Ahmed <mirahmed753@gmail.com>
Co-authored-by: Dan Gohman <sunfish@mozilla.com>
This commit is contained in:
Carmen Kwan
2019-07-23 16:28:54 -07:00
committed by Dan Gohman
parent b659262d2a
commit 19257f80c1
47 changed files with 1027 additions and 62 deletions

View File

@@ -1,7 +1,9 @@
//! Defines `SimpleJITBackend`.
use crate::memory::Memory;
use cranelift_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSink};
use cranelift_codegen::binemit::{
Addend, CodeOffset, NullTrapSink, Reloc, RelocSink, Stackmap, StackmapSink,
};
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::{self, ir, settings};
use cranelift_module::{
@@ -128,6 +130,13 @@ struct RelocRecord {
addend: Addend,
}
struct StackmapRecord {
#[allow(dead_code)]
offset: CodeOffset,
#[allow(dead_code)]
stackmap: Stackmap,
}
pub struct SimpleJITCompiledFunction {
code: *mut u8,
size: usize,
@@ -254,7 +263,16 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
// Ignore traps for now. For now, frontends should just avoid generating code
// that traps.
let mut trap_sink = NullTrapSink {};
unsafe { ctx.emit_to_memory(&*self.isa, ptr, &mut reloc_sink, &mut trap_sink) };
let mut stackmap_sink = SimpleJITStackmapSink::new();
unsafe {
ctx.emit_to_memory(
&*self.isa,
ptr,
&mut reloc_sink,
&mut trap_sink,
&mut stackmap_sink,
)
};
Ok(Self::CompiledFunction {
code: ptr,
@@ -549,3 +567,21 @@ impl RelocSink for SimpleJITRelocSink {
}
}
}
struct SimpleJITStackmapSink {
pub stackmaps: Vec<StackmapRecord>,
}
impl SimpleJITStackmapSink {
pub fn new() -> Self {
Self {
stackmaps: Vec::new(),
}
}
}
impl StackmapSink for SimpleJITStackmapSink {
fn add_stackmap(&mut self, offset: CodeOffset, stackmap: Stackmap) {
self.stackmaps.push(StackmapRecord { offset, stackmap });
}
}