feat(runtime-core) Feed imported functions with vm::Ctx again.

… and look for the associated `vm::FuncCtx`. This way, we don't break
the rule: “all functions receive a vmctx pointer as first argument.”.
This commit is contained in:
Ivan Enderlin
2019-11-11 21:45:46 +01:00
parent ba87af5b1a
commit 98e4ef066a
2 changed files with 55 additions and 6 deletions

View File

@ -691,7 +691,9 @@ impl FuncEnvironment for FunctionEnvironment {
}
/// Generates a call IR with `callee` and `call_args` and inserts it at `pos`
/// TODO: add support for imported functions
///
/// It's about generating code that calls a local or imported function; in
/// WebAssembly: `(call $foo)`.
fn translate_call(
&mut self,
mut pos: FuncCursor,
@ -771,14 +773,23 @@ impl FuncEnvironment for FunctionEnvironment {
readonly: true,
});
let imported_func_ctx_vmctx_addr =
pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_ctx_addr,
offset: (0 as i32).into(),
global_type: ptr_type,
readonly: true,
});
let imported_func_addr = pos.ins().global_value(ptr_type, imported_func_addr);
let imported_func_ctx_addr =
pos.ins().global_value(ptr_type, imported_func_ctx_addr);
let imported_func_ctx_vmctx_addr = pos
.ins()
.global_value(ptr_type, imported_func_ctx_vmctx_addr);
let sig_ref = pos.func.dfg.ext_funcs[callee].signature;
let mut args = Vec::with_capacity(call_args.len() + 1);
args.push(imported_func_ctx_addr);
args.push(imported_func_ctx_vmctx_addr);
args.extend(call_args.iter().cloned());
Ok(pos