Add a hook to the wasm FuncEnvironment for emitting loop headers.

This will allow wasm implementations that wish to insert code into
every loop, for example to insert an interrupt check or a safepoint.
do so without relying on asynchronous signals.
This commit is contained in:
Dan Gohman
2018-03-18 13:47:17 -07:00
parent 492fa1283c
commit d99b43e4b7
2 changed files with 9 additions and 0 deletions

View File

@@ -137,6 +137,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
builder.ins().jump(loop_body, &[]); builder.ins().jump(loop_body, &[]);
state.push_loop(loop_body, next, num_return_values(ty)); state.push_loop(loop_body, next, num_return_values(ty));
builder.switch_to_block(loop_body); builder.switch_to_block(loop_body);
environ.translate_loop_header(builder.cursor());
} }
Operator::If { ty } => { Operator::If { ty } => {
let val = state.pop1(); let val = state.pop1();

View File

@@ -144,6 +144,14 @@ pub trait FuncEnvironment {
index: MemoryIndex, index: MemoryIndex,
heap: ir::Heap, heap: ir::Heap,
) -> ir::Value; ) -> ir::Value;
/// Emit code at the beginning of every wasm loop.
///
/// This can be used to insert explicit interrupt or safepoint checking at
/// the beginnings of loops.
fn translate_loop_header(&mut self, _pos: FuncCursor) {
// By default, don't emit anything.
}
} }
/// An object satisfying the `ModuleEnvironment` trait can be passed as argument to the /// An object satisfying the `ModuleEnvironment` trait can be passed as argument to the