Move WasmRuntime::translate_call_indirect() into FuncEnvironment.

Add two new arguments:

- table_index is the WebAssembly table referenced in the indirect call.
- sig_index is the WebAssembly signature index. We still have the SigRef
  that was created by make_indirect_sig(), but the WebAssembly signature
  index may be needed for detecting type mismatches at runtime.

Change the insertion location to a plain FuncCursor rather than a
FunctionBuilder<Local>. The fact that cretonne-wasm uses FunctionBuilder
should be an implementation detail, and the callbacks don't need to
access WebAssembly locals, so they don't need the extended interface.

Add a FunctionBuilder::cursor() method which creates a FuncCursor for
inserting instructions in the current EBB.

Also add a FuncEnvironment::translate_call() method which allows the
environment to override direct calls the same way as indirect calls.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-06 15:06:28 -07:00
parent dc2bee9cef
commit 26048c2ecc
7 changed files with 129 additions and 54 deletions

View File

@@ -2,8 +2,9 @@ use runtime::{FuncEnvironment, GlobalValue, WasmRuntime};
use translation_utils::{Local, Global, Memory, Table, GlobalIndex, TableIndex, SignatureIndex,
FunctionIndex, MemoryIndex};
use cton_frontend::FunctionBuilder;
use cretonne::ir::{self, Value, InstBuilder, SigRef};
use cretonne::ir::{self, Value, InstBuilder};
use cretonne::ir::types::*;
use cretonne::cursor::FuncCursor;
/// This runtime implementation is a "naïve" one, doing essentially nothing and emitting
/// placeholders when forced to. Don't try to execute code translated with this runtime, it is
@@ -75,6 +76,18 @@ impl FuncEnvironment for DummyRuntime {
func.dfg.ext_funcs.push(ir::ExtFuncData { name, signature })
}
fn translate_call_indirect(
&self,
mut pos: FuncCursor,
_table_index: TableIndex,
_sig_index: SignatureIndex,
sig_ref: ir::SigRef,
callee: ir::Value,
call_args: &[ir::Value],
) -> ir::Inst {
pos.ins().call_indirect(sig_ref, callee, call_args)
}
}
impl WasmRuntime for DummyRuntime {
@@ -84,16 +97,6 @@ impl WasmRuntime for DummyRuntime {
fn translate_current_memory(&mut self, builder: &mut FunctionBuilder<Local>) -> Value {
builder.ins().iconst(I32, -1)
}
fn translate_call_indirect<'a>(
&self,
builder: &'a mut FunctionBuilder<Local>,
sig_ref: SigRef,
index_val: Value,
call_args: &[Value],
) -> &'a [Value] {
let call_inst = builder.ins().call_indirect(sig_ref, index_val, call_args);
builder.inst_results(call_inst)
}
fn declare_signature(&mut self, sig: &ir::Signature) {
self.signatures.push(sig.clone());