Skip to content

Commit

Permalink
Merge branch 'master' into feat-runtime-core-field-offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan authored Nov 13, 2019
2 parents 0775d49 + d64d070 commit 8f20a28
Show file tree
Hide file tree
Showing 13 changed files with 680 additions and 252 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## **[Unreleased]**

## 0.10.0 - 2019-11-11
- [#925](https://github.com/wasmerio/wasmer/pull/925) Host functions can be closures with a captured environment.
- [#917](https://github.com/wasmerio/wasmer/pull/917) Host functions (aka imported functions) may not have `&mut vm::Ctx` as first argument, i.e. the presence of the `&mut vm::Ctx` argument is optional.
- [#915](https://github.com/wasmerio/wasmer/pull/915) All backends share the same definition of `Trampoline` (defined in `wasmer-runtime-core`).

## 0.10.1 - 2019-11-11

- [#952](https://github.com/wasmerio/wasmer/pull/952) Use C preprocessor to properly hide trampoline functions on Windows and non-x86_64 targets.

Expand Down
31 changes: 22 additions & 9 deletions lib/clif-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -763,20 +765,31 @@ impl FuncEnvironment for FunctionEnvironment {
readonly: true,
});

let imported_vmctx_addr = pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_struct_addr,
offset: (vm::ImportedFunc::offset_vmctx() as i32).into(),
global_type: ptr_type,
readonly: true,
});
let imported_func_ctx_addr =
pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_struct_addr,
offset: (vm::ImportedFunc::offset_func_ctx() as i32).into(),
global_type: ptr_type,
readonly: true,
});

let imported_func_ctx_vmctx_addr =
pos.func.create_global_value(ir::GlobalValueData::Load {
base: imported_func_ctx_addr,
offset: (vm::FuncCtx::offset_vmctx() as i32).into(),
global_type: ptr_type,
readonly: true,
});

let imported_func_addr = pos.ins().global_value(ptr_type, imported_func_addr);
let imported_vmctx_addr = pos.ins().global_value(ptr_type, imported_vmctx_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_vmctx_addr);
args.push(imported_func_ctx_vmctx_addr);
args.extend(call_args.iter().cloned());

Ok(pos
Expand Down
7 changes: 7 additions & 0 deletions lib/clif-backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! The Wasmer Cranelift Backend crate is used to compile wasm binary code via parse events from the
//! Wasmer runtime common parser code into machine code.
//!
#![deny(
dead_code,
missing_docs,
nonstandard_style,
unused_imports,
unused_mut,
Expand Down Expand Up @@ -53,6 +58,8 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");

use wasmer_runtime_core::codegen::SimpleStreamingCompilerGen;

/// Streaming compiler implementation for the Cranelift backed. Compiles web assembly binary into
/// machine code.
pub type CraneliftCompiler = SimpleStreamingCompilerGen<
code::CraneliftModuleCodeGenerator,
code::CraneliftFunctionCodeGenerator,
Expand Down
17 changes: 13 additions & 4 deletions lib/llvm-backend/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ impl Intrinsics {
context.struct_type(&[i8_ptr_ty_basic, i64_ty_basic, i8_ptr_ty_basic], false);
let local_table_ty = local_memory_ty;
let local_global_ty = i64_ty;
let imported_func_ty =
context.struct_type(&[i8_ptr_ty_basic, ctx_ptr_ty.as_basic_type_enum()], false);
let func_ctx_ty =
context.struct_type(&[ctx_ptr_ty.as_basic_type_enum(), i8_ptr_ty_basic], false);
let func_ctx_ptr_ty = func_ctx_ty.ptr_type(AddressSpace::Generic);
let imported_func_ty = context.struct_type(
&[i8_ptr_ty_basic, func_ctx_ptr_ty.as_basic_type_enum()],
false,
);
let sigindex_ty = i32_ty;
let rt_intrinsics_ty = i8_ty;
let stack_lower_bound_ty = i8_ty;
Expand Down Expand Up @@ -1066,16 +1071,20 @@ impl<'a> CtxType<'a> {
"imported_func_ptr",
)
};
let (func_ptr_ptr, ctx_ptr_ptr) = unsafe {
let (func_ptr_ptr, func_ctx_ptr_ptr) = unsafe {
(
cache_builder.build_struct_gep(imported_func_ptr, 0, "func_ptr_ptr"),
cache_builder.build_struct_gep(imported_func_ptr, 1, "ctx_ptr_ptr"),
cache_builder.build_struct_gep(imported_func_ptr, 1, "func_ctx_ptr_ptr"),
)
};

let func_ptr = cache_builder
.build_load(func_ptr_ptr, "func_ptr")
.into_pointer_value();
let func_ctx_ptr = cache_builder
.build_load(func_ctx_ptr_ptr, "func_ctx_ptr")
.into_pointer_value();
let ctx_ptr_ptr = unsafe { cache_builder.build_struct_gep(func_ctx_ptr, 0, "ctx_ptr") };
let ctx_ptr = cache_builder
.build_load(ctx_ptr_ptr, "ctx_ptr")
.into_pointer_value();
Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/src/stackmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl StackmapEntry {
ValueSemantic::ImportedFuncCtx(idx) => MachineValue::VmctxDeref(vec![
Ctx::offset_imported_funcs() as usize,
vm::ImportedFunc::size() as usize * idx
+ vm::ImportedFunc::offset_vmctx() as usize,
+ vm::ImportedFunc::offset_func_ctx() as usize,
0,
]),
ValueSemantic::DynamicSigindice(idx) => {
Expand Down
Loading

0 comments on commit 8f20a28

Please sign in to comment.