Skip to content

Commit

Permalink
Merge branch 'master' into import-object-state-creator-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YaronWittenstein committed Dec 5, 2019
2 parents a54bcb6 + af7a368 commit 850528e
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 97 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## **[Unreleased]**

- [#1029](https://github.com/wasmerio/wasmer/pull/1029) Add the “floating” `WasiVersion::Latest` version.
- [#1006](https://github.com/wasmerio/wasmer/pull/1006) Fix minor panic issue when `wasmer::compile_with` called with llvm backend
- [#1009](https://github.com/wasmerio/wasmer/pull/1009) Enable LLVM verifier for all tests, add new llvm-backend-tests crate.
- [#1022](https://github.com/wasmerio/wasmer/pull/1022) Add caching support for Singlepass backend.
- [#1004](https://github.com/wasmerio/wasmer/pull/1004) Add the Auto backend to enable to adapt backend usage depending on wasm file executed.

## 0.11.0 - 2019-11-22
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<a href="https://dev.azure.com/wasmerio/wasmer/_build/latest?definitionId=3&branchName=master">
<img src="https://img.shields.io/azure-devops/build/wasmerio/wasmer/3.svg?style=flat-square" alt="Build Status">
</a>
<a href="https://docs.wasmer.io">
<img src="https://img.shields.io/badge/Docs-docs.wasmer.io-blue?style=flat-square" alt="Documentation">
</a>
<a href="https://github.com/wasmerio/wasmer/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square" alt="License">
</a>
Expand All @@ -23,7 +26,7 @@

[Wasmer](https://wasmer.io/) is a standalone WebAssembly runtime for running WebAssembly [outside of the browser](https://webassembly.org/docs/non-web/), supporting [WASI](https://github.com/WebAssembly/WASI) and [Emscripten](https://emscripten.org/). Wasmer can be used standalone (via the CLI) and embedded in different languages, running in x86 and [ARM devices](https://medium.com/wasmer/running-webassembly-on-arm-7d365ed0e50c).

Install the Wasmer CLI with:
Install the Wasmer and [WAPM](https://wapm.io) cli with:

```sh
curl https://get.wasmer.io -sSfL | sh
Expand Down Expand Up @@ -59,28 +62,15 @@ Once installed, you will be able to run any WebAssembly files (_including Lua, P

```sh
# Run Lua
wasmer run examples/lua.wasm
wasmer examples/lua.wasm
```

*You can find more `wasm/wat` examples in the [examples](./examples) directory.*

#### With wapm

Installing Wasmer through `wasmer.io` includes
[`wapm`](https://github.com/wasmerio/wapm-cli), the [WebAssembly Package Manager](https://wapm.io/).

wapm allows you to easily download, run, and distribute WebAssembly binaries.
### Docs

```sh
# Install cowsay globally
wapm install -g cowsay

# Run cowsay
wapm run cowsay "Hello, world!"
```
Wasmer documentation lives on [docs.wasmer.io](https://docs.wasmer.io).

For more information about wapm, check out the [website](https://www.wapm.io)
and this [example program](https://github.com/wapm-packages/rust-wasi-example).

## Code Structure

Expand Down Expand Up @@ -259,8 +249,8 @@ Below are some of the goals of this project (in order of priority):
- [x] It should be 100% compatible with the [WebAssembly spec tests](https://github.com/wasmerio/wasmer/tree/master/lib/spectests/spectests)
- [x] It should be fast _(partially achieved)_
- [x] Support WASI - released in [0.3.0](https://github.com/wasmerio/wasmer/releases/tag/0.3.0)
- [x] Support Emscripten calls _(in the works)_
- [ ] Support Go JS ABI calls
- [x] Support Emscripten calls
- [ ] Support Go JS ABI calls _(in the works)_

## Architecture

Expand Down
4 changes: 2 additions & 2 deletions docs/feature_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

| &nbsp; | Singlepass | Cranelift | LLVM |
| - | :-: | :-: | :-: |
| Caching | |||
| Caching | |||
| Emscripten ||||
| Metering ||||
| Multi-value return ||||
| OSR | 🔄 | | |
| OSR | 🔄 | | 🔄 |
| SIMD ||||
| WASI ||||
| WASMER_BACKTRACE ||||
Expand Down
4 changes: 2 additions & 2 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub struct EmscriptenData<'a> {
pub dyn_call_iii: Option<Func<'a, (i32, i32, i32), i32>>,
pub dyn_call_iiii: Option<Func<'a, (i32, i32, i32, i32), i32>>,
pub dyn_call_iifi: Option<Func<'a, (i32, i32, f64, i32), i32>>,
pub dyn_call_v: Option<Func<'a, (i32)>>,
pub dyn_call_v: Option<Func<'a, i32>>,
pub dyn_call_vi: Option<Func<'a, (i32, i32)>>,
pub dyn_call_vii: Option<Func<'a, (i32, i32, i32)>>,
pub dyn_call_viii: Option<Func<'a, (i32, i32, i32, i32)>>,
Expand Down Expand Up @@ -168,7 +168,7 @@ pub struct EmscriptenData<'a> {
pub temp_ret_0: i32,

pub stack_save: Option<Func<'a, (), i32>>,
pub stack_restore: Option<Func<'a, (i32)>>,
pub stack_restore: Option<Func<'a, i32>>,
pub set_threw: Option<Func<'a, (i32, i32)>>,
pub mapped_dirs: HashMap<String, PathBuf>,
}
Expand Down
7 changes: 4 additions & 3 deletions lib/emscripten/src/syscalls/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use libc::{
accept,
access,
bind,
c_char,
c_int,
c_ulong,
c_void,
Expand Down Expand Up @@ -1063,14 +1064,14 @@ pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
let upper_bound = std::cmp::min((*dirent).d_reclen, 255) as usize;
let mut i = 0;
while i < upper_bound {
*(dirp.add(pos + 11 + i) as *mut i8) = (*dirent).d_name[i] as _;
*(dirp.add(pos + 11 + i) as *mut c_char) = (*dirent).d_name[i] as c_char;
i += 1;
}
// We set the termination string char
*(dirp.add(pos + 11 + i) as *mut i8) = 0 as i8;
*(dirp.add(pos + 11 + i) as *mut c_char) = 0 as c_char;
debug!(
" => file {}",
CStr::from_ptr(dirp.add(pos + 11) as *const i8)
CStr::from_ptr(dirp.add(pos + 11) as *const c_char)
.to_str()
.unwrap()
);
Expand Down
20 changes: 19 additions & 1 deletion lib/llvm-backend-tests/tests/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,23 @@ fn crash_return_with_float_on_stack() {
"#;
let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed");
let module = compile_with(&wasm_binary, &get_compiler()).unwrap();
let instance = module.instantiate(&imports! {}).unwrap();
module.instantiate(&imports! {}).unwrap();
}

#[test]
fn crash_select_with_mismatched_pending() {
const MODULE: &str = r#"
(module
(func (param f64)
f64.const 0x0p+0 (;=0;)
local.get 0
f64.add
f64.const 0x0p+0 (;=0;)
i32.const 0
select
drop))
"#;
let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed");
let module = compile_with(&wasm_binary, &get_compiler()).unwrap();
module.instantiate(&imports! {}).unwrap();
}
6 changes: 4 additions & 2 deletions lib/llvm-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,15 +1730,17 @@ impl<'ctx> FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator<'ct
// If the pending bits of v1 and v2 are the same, we can pass
// them along to the result. Otherwise, apply pending
// canonicalizations now.
let (v1, v2) = if i1.has_pending_f32_nan() != i2.has_pending_f32_nan()
let (v1, i1, v2, i2) = if i1.has_pending_f32_nan() != i2.has_pending_f32_nan()
|| i1.has_pending_f64_nan() != i2.has_pending_f64_nan()
{
(
apply_pending_canonicalization(builder, intrinsics, v1, i1),
i1.strip_pending(),
apply_pending_canonicalization(builder, intrinsics, v2, i2),
i2.strip_pending(),
)
} else {
(v1, v2)
(v1, i1, v2, i2)
};
let cond_value = builder.build_int_compare(
IntPredicate::NE,
Expand Down
4 changes: 2 additions & 2 deletions lib/middleware-common-tests/benches/metering_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn bench_metering(c: &mut Criterion) {
let wasm_binary = wat2wasm(WAT).unwrap();
let module = compile_with(&wasm_binary, &compiler).unwrap();
let import_object = imports! {};
let mut instance = module.instantiate(&import_object).unwrap();
let instance = module.instantiate(&import_object).unwrap();
let add_to: Func<(i32, i32), i32> = instance.func("add_to").unwrap();
b.iter(|| black_box(add_to.call(100, 4)))
})
Expand All @@ -202,7 +202,7 @@ fn bench_metering(c: &mut Criterion) {
"gas" => Func::new(gas),
},
};
let mut gas_instance = gas_module.instantiate(&gas_import_object).unwrap();
let gas_instance = gas_module.instantiate(&gas_import_object).unwrap();
let gas_add_to: Func<(i32, i32), i32> = gas_instance.func("add_to").unwrap();
b.iter(|| black_box(gas_add_to.call(100, 4)))
})
Expand Down
18 changes: 9 additions & 9 deletions lib/runtime-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::collections::BTreeMap;
use std::ops::Bound::{Included, Unbounded};

/// An index to a register
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct RegisterIndex(pub usize);

/// A kind of wasm or constant value
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum WasmAbstractValue {
/// A wasm runtime value
Runtime,
Expand All @@ -20,7 +20,7 @@ pub enum WasmAbstractValue {
}

/// A container for the state of a running wasm instance.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MachineState {
/// Stack values.
pub stack_values: Vec<MachineValue>,
Expand All @@ -37,7 +37,7 @@ pub struct MachineState {
}

/// A diff of two `MachineState`s.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct MachineStateDiff {
/// Last.
pub last: Option<usize>,
Expand All @@ -63,7 +63,7 @@ pub struct MachineStateDiff {
}

/// A kind of machine value.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum MachineValue {
/// Undefined.
Undefined,
Expand All @@ -86,7 +86,7 @@ pub enum MachineValue {
}

/// A map of function states.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FunctionStateMap {
/// Initial.
pub initial: MachineState,
Expand All @@ -111,7 +111,7 @@ pub struct FunctionStateMap {
}

/// A kind of suspend offset.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum SuspendOffset {
/// A loop.
Loop(usize),
Expand All @@ -122,7 +122,7 @@ pub enum SuspendOffset {
}

/// Info for an offset.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OffsetInfo {
/// End offset.
pub end_offset: usize, // excluded bound
Expand All @@ -133,7 +133,7 @@ pub struct OffsetInfo {
}

/// A map of module state.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ModuleStateMap {
/// Local functions.
pub local_functions: BTreeMap<usize, FunctionStateMap>,
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/benches/many_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::Criterion;
use tempfile::tempdir;
use wasmer_runtime::{
cache::{Cache, FileSystemCache, WasmHash},
compile, func, imports, instantiate, validate, ImportObject,
compile, func, imports, instantiate, validate,
};
use wasmer_runtime_core::vm::Ctx;

Expand Down Expand Up @@ -71,7 +71,7 @@ fn calling_fn_benchmark(c: &mut Criterion) {
);
let instance = instantiate(SIMPLE_WASM, &imports).unwrap();
c.bench_function("calling fn", move |b| {
let entry_point = instance.func::<(i32), i32>("plugin_entrypoint").unwrap();
let entry_point = instance.func::<i32, i32>("plugin_entrypoint").unwrap();
b.iter(|| entry_point.call(2).unwrap())
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Cache for FileSystemCache {
}
}

#[cfg(all(test, not(feature = "singlepass")))]
#[cfg(test)]
mod tests {

use super::*;
Expand Down
3 changes: 3 additions & 0 deletions lib/singlepass-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ byteorder = "1.3"
nix = "0.15"
libc = "0.2.60"
smallvec = "0.6"
serde = "1.0"
serde_derive = "1.0"
bincode = "1.2"
Loading

0 comments on commit 850528e

Please sign in to comment.