diff --git a/.circleci/config.yml b/.circleci/config.yml index 3490bf6b539..67309e90320 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,7 +21,8 @@ jobs: - checkout - restore_cache: keys: - - v6-lint-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-lint-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-lint-{{ arch }} - <<: *run_install_dependencies - run: name: Install lint deps @@ -40,7 +41,7 @@ jobs: - target/debug/.fingerprint - target/debug/build - target/debug/deps - key: v6-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} + key: v8-lint-{{ arch }}-{{ checksum "Cargo.lock" }} test: docker: @@ -50,14 +51,17 @@ jobs: - checkout - restore_cache: keys: - - v6-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-test-cargo-cache-linux-stable-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-test-cargo-cache-linux-stable-{{ arch }} - <<: *run_install_dependencies - run: name: Tests command: make test - run: name: Emscripten Tests - command: make test-emscripten + command: | + make test-emscripten-clif + make test-emscripten-llvm - run: name: Integration Tests command: make integration-tests @@ -67,7 +71,7 @@ jobs: - target/debug/.fingerprint - target/debug/build - target/debug/deps - key: v6-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} + key: v8-test-cargo-cache-linux-stable-{{ arch }}-{{ checksum "Cargo.lock" }} test-macos: macos: @@ -76,7 +80,8 @@ jobs: - checkout - restore_cache: keys: - - v6-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-darwin-stable-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-darwin-stable-{{ arch }} - run: name: Install crate dependencies command: | @@ -112,7 +117,8 @@ jobs: # We increase the ulimit for fixing cargo unclosed files in mac ulimit -n 8000 sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680 - make test-emscripten + make test-emscripten-clif + make test-emscripten-llvm - run: name: Integration Tests command: | @@ -129,7 +135,7 @@ jobs: - target/release/.fingerprint - target/release/build - target/release/deps - key: v6-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }} + key: v8-cargo-cache-darwin-stable-{{ arch }}-{{ checksum "Cargo.lock" }} test-and-build: docker: @@ -138,13 +144,16 @@ jobs: - checkout - restore_cache: keys: - - v6-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-linux-nightly-{{ arch }} - run: name: Install dependencies command: | sudo apt-get install -y cmake curl -O https://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz tar xf clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz + # Use rust nightly (for singlepass, for now) + - run: rustup default nightly-2019-04-11 - run: name: Tests command: | @@ -154,7 +163,8 @@ jobs: name: Emscripten Tests command: | export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/" - make test-emscripten + make test-emscripten-clif + make test-emscripten-llvm - run: name: Release Build command: | @@ -183,7 +193,7 @@ jobs: - target/release/.fingerprint - target/release/build - target/release/deps - key: v6-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} + key: v8-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} test-and-build-macos: macos: @@ -192,7 +202,8 @@ jobs: - checkout - restore_cache: keys: - - v6-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-darwin-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-darwin-nightly-{{ arch }} - run: name: Install crate dependencies command: | @@ -209,6 +220,8 @@ jobs: curl https://sh.rustup.rs -sSf | sh -s -- -y export PATH="$HOME/.cargo/bin:$PATH" cargo --version + # Use rust nightly (for singlepass, for now) + - run: rustup default nightly-2019-04-11 - run: name: Tests command: | @@ -228,7 +241,8 @@ jobs: # We increase the ulimit for fixing cargo unclosed files in mac ulimit -n 8000 sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680 - make test-emscripten + make test-emscripten-clif + make test-emscripten-singlepass - run: name: Release Build command: | @@ -253,7 +267,7 @@ jobs: - target/release/.fingerprint - target/release/build - target/release/deps - key: v6-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }} + key: v8-cargo-cache-darwin-nightly-{ arch }}-{{ checksum "Cargo.lock" }} test-rust-nightly: docker: @@ -262,27 +276,28 @@ jobs: - checkout - restore_cache: keys: - - v6-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}-nightly + - v8-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} + - v8-cargo-cache-linux-nightly-{{ arch }} - run: name: Install dependencies command: | sudo apt-get install -y cmake curl -O https://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz tar xf clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz - - run: rustup default nightly-2019-02-27 + - run: rustup default nightly-2019-04-11 - run: | export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/" make test - make test-nightly + make test-singlepass make test-emscripten-clif - make test-emscripten-nightly + make test-emscripten-singlepass - save_cache: paths: - /usr/local/cargo/registry - target/debug/.fingerprint - target/debug/build - target/debug/deps - key: v6-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}-nightly + key: v8-cargo-cache-linux-nightly-{{ arch }}-{{ checksum "Cargo.lock" }}-nightly publish-github-release: docker: diff --git a/Cargo.lock b/Cargo.lock index a82cca2b353..fec3babbb58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2230,12 +2230,12 @@ dependencies = [ "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-dynasm-backend 0.1.0", "wasmer-emscripten 0.2.1", "wasmer-llvm-backend 0.1.0", "wasmer-runtime 0.2.1", "wasmer-runtime-abi 0.2.1", "wasmer-runtime-core 0.2.1", + "wasmer-singlepass-backend 0.1.0", "wasmer-wasi 0.2.1", ] @@ -2263,22 +2263,6 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "wasmer-dynasm-backend" -version = "0.1.0" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dynasm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime-core 0.2.1", - "wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "wasmer-emscripten" version = "0.2.1" @@ -2291,9 +2275,9 @@ dependencies = [ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-dynasm-backend 0.1.0", "wasmer-llvm-backend 0.1.0", "wasmer-runtime-core 0.2.1", + "wasmer-singlepass-backend 0.1.0", ] [[package]] @@ -2327,9 +2311,9 @@ dependencies = [ "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-dynasm-backend 0.1.0", "wasmer-llvm-backend 0.1.0", "wasmer-runtime-core 0.2.1", + "wasmer-singlepass-backend 0.1.0", ] [[package]] @@ -2382,15 +2366,31 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasmer-singlepass-backend" +version = "0.1.0" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dynasm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-runtime-core 0.2.1", + "wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wasmer-spectests" version = "0.2.0" dependencies = [ "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.2.0", - "wasmer-dynasm-backend 0.1.0", "wasmer-llvm-backend 0.1.0", "wasmer-runtime-core 0.2.1", + "wasmer-singlepass-backend 0.1.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 244581f8d97..a82a52ef1d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ structopt = "0.2.11" wabt = "0.7.2" hashbrown = "0.1.8" wasmer-clif-backend = { path = "lib/clif-backend" } -wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true } +wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true } wasmer-runtime = { path = "lib/runtime" } wasmer-runtime-abi = { path = "lib/runtime-abi", optional = true } wasmer-runtime-core = { path = "lib/runtime-core" } @@ -33,18 +33,18 @@ wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true } wasmer-wasi = { path = "lib/wasi", optional = true } [workspace] -members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-abi", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi"] +members = ["lib/clif-backend", "lib/singlepass-backend", "lib/runtime", "lib/runtime-abi", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi"] [build-dependencies] wabt = "0.7.2" glob = "0.2.11" [features] -default = ["fast-tests", "wasi"] +default = ["fast-tests", "wasi", "singlepass", "llvm"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] # This feature will allow cargo test to run much faster fast-tests = [] -llvm = ["wasmer-llvm-backend", "wasmer-runtime/llvm"] -dynasm = ["wasmer-dynasm-backend", "wasmer-runtime/dynasm"] +llvm = ["wasmer-llvm-backend"] +singlepass = ["wasmer-singlepass-backend"] wasi = ["wasmer-wasi"] vfs = ["wasmer-runtime-abi"] diff --git a/Makefile b/Makefile index 383d4ccf4ab..2b87dd7e7de 100644 --- a/Makefile +++ b/Makefile @@ -34,34 +34,33 @@ precommit: lint test test: # We use one thread so the emscripten stdouts doesn't collide - cargo test --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests --exclude wasmer-dynasm-backend -- $(runargs) + cargo test --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests --exclude wasmer-singlepass-backend -- $(runargs) # cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs) cargo test --manifest-path lib/spectests/Cargo.toml --features clif cargo test --manifest-path lib/spectests/Cargo.toml --features llvm cargo build -p wasmer-runtime-c-api cargo test -p wasmer-runtime-c-api -- --nocapture -test-nightly: - cargo test --manifest-path lib/spectests/Cargo.toml --features dynasm +test-singlepass: + cargo test --manifest-path lib/spectests/Cargo.toml --features singlepass -test-emscripten: - cargo test --manifest-path lib/emscripten/Cargo.toml --features clif -- --test-threads=1 $(runargs) +test-emscripten-llvm: cargo test --manifest-path lib/emscripten/Cargo.toml --features llvm -- --test-threads=1 $(runargs) test-emscripten-clif: cargo test --manifest-path lib/emscripten/Cargo.toml --features clif -- --test-threads=1 $(runargs) -test-emscripten-nightly: - cargo test --manifest-path lib/emscripten/Cargo.toml --features dynasm -- --test-threads=1 $(runargs) +test-emscripten-singlepass: + cargo test --manifest-path lib/emscripten/Cargo.toml --features singlepass -- --test-threads=1 $(runargs) -dynasm-debug-release: - cargo +nightly build --features "dynasm debug" --release +singlepass-debug-release: + cargo +nightly build --features "singlepass debug" --release -dynasm-release: - cargo +nightly build --features "dynasm" --release +singlepass-release: + cargo +nightly build --features "singlepass" --release -dynasm-build: - cargo +nightly build --features "dynasm debug" +singlepass-build: + cargo +nightly build --features "singlepass debug" release: # If you are in OS-X, you will need mingw-w64 for cross compiling to windows diff --git a/lib/README.md b/lib/README.md index b8a99dd6d68..83a3355886c 100644 --- a/lib/README.md +++ b/lib/README.md @@ -34,6 +34,6 @@ to tune the codegen properties (compile speed, performance, etc) to best fit the Currently, we support multiple backends for compiling WebAssembly to machine code: -- [dynasm-backend](./dynasm-backend/): Dynasm backend - super fast compilation, slower runtime speed +- [singlepass-backend](./singlepass-backend/): Single pass backend - super fast compilation, slower runtime speed - [clif-backend](./clif-backend/): Cranelift backend - slower compilation, normal runtime speed - [llvm-backend](./llvm-backend/): LLVM backend - slow compilation, native runtime speed diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index 5c59db3506d..8b19340b0a7 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -15,7 +15,7 @@ libc = "0.2.49" byteorder = "1" time = "0.1.41" wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" } -wasmer-dynasm-backend = { path = "../dynasm-backend", version = "0.1.0", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.1.0", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.1.0", optional = true } [target.'cfg(windows)'.dependencies] @@ -30,5 +30,5 @@ glob = "0.2.11" [features] clif = [] llvm = ["wasmer-llvm-backend"] -dynasm = ["wasmer-dynasm-backend"] +singlepass = ["wasmer-singlepass-backend"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 725f0ba9408..e1cf13ef516 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -186,13 +186,13 @@ mod tests { LLVMCompiler::new() } - #[cfg(feature = "dynasm")] + #[cfg(feature = "singlepass")] fn get_compiler() -> impl Compiler { - use wasmer_dynasm_backend::SinglePassCompiler; + use wasmer_singlepass_backend::SinglePassCompiler; SinglePassCompiler::new() } - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "dynasm")))] + #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] fn get_compiler() -> impl Compiler { panic!("compiler not specified, activate a compiler via features"); use wasmer_clif_backend::CraneliftCompiler; diff --git a/lib/emscripten/tests/emtests/_common.rs b/lib/emscripten/tests/emtests/_common.rs index ca5f6028265..18664e4eac7 100644 --- a/lib/emscripten/tests/emtests/_common.rs +++ b/lib/emscripten/tests/emtests/_common.rs @@ -20,13 +20,13 @@ macro_rules! assert_emscripten_output { LLVMCompiler::new() } - #[cfg(feature = "dynasm")] + #[cfg(feature = "singlepass")] fn get_compiler() -> impl Compiler { - use wasmer_dynasm_backend::SinglePassCompiler; + use wasmer_singlepass_backend::SinglePassCompiler; SinglePassCompiler::new() } - #[cfg(not(any(feature = "llvm", feature = "clif", feature = "dynasm")))] + #[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] fn get_compiler() -> impl Compiler { panic!("compiler not specified, activate a compiler via features"); use wasmer_clif_backend::CraneliftCompiler; diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 1e528651d92..1044a7ee56a 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -25,7 +25,7 @@ pub use crate::sig_registry::SigRegistry; #[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)] pub enum Backend { Cranelift, - Dynasm, + Singlepass, LLVM, } diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index c137922f063..f34798bf550 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" readme = "README.md" [dependencies] -wasmer-dynasm-backend = { path = "../dynasm-backend", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", optional = true } lazy_static = "1.2.0" memmap = "0.7.0" @@ -37,7 +37,7 @@ default-compiler = ["wasmer-clif-backend"] cache = ["default-compiler"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] llvm = ["wasmer-llvm-backend"] -dynasm = ["wasmer-dynasm-backend"] +singlepass = ["wasmer-singlepass-backend"] [[bench]] name = "nginx" diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index a45faddc1c7..1836bb206be 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -141,6 +141,16 @@ pub fn compile_with_config( wasmer_runtime_core::compile_with_config(&wasm[..], default_compiler(), compiler_config) } +/// The same as `compile_with_config` but takes a `Compiler` for the purpose of +/// changing the backend. +pub fn compile_with_config_with( + wasm: &[u8], + compiler_config: CompilerConfig, + compiler: &dyn Compiler, +) -> error::CompileResult { + wasmer_runtime_core::compile_with_config(&wasm[..], compiler, compiler_config) +} + /// Compile and instantiate WebAssembly code without /// creating a [`Module`]. /// @@ -171,10 +181,10 @@ pub fn default_compiler() -> &'static dyn Compiler { #[cfg(feature = "llvm")] use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler; - #[cfg(feature = "dynasm")] - use wasmer_dynasm_backend::SinglePassCompiler as DefaultCompiler; + #[cfg(feature = "singlepass")] + use wasmer_singlepass_backend::SinglePassCompiler as DefaultCompiler; - #[cfg(not(any(feature = "llvm", feature = "dynasm")))] + #[cfg(not(any(feature = "llvm", feature = "singlepass")))] use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler; lazy_static! { diff --git a/lib/dynasm-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml similarity index 81% rename from lib/dynasm-backend/Cargo.toml rename to lib/singlepass-backend/Cargo.toml index 3f6ef866720..977a3eac6b0 100644 --- a/lib/dynasm-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "wasmer-dynasm-backend" +name = "wasmer-singlepass-backend" version = "0.1.0" repository = "https://github.com/wasmerio/wasmer" -description = "Wasmer runtime Dynasm compiler backend" +description = "Wasmer runtime single pass compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] edition = "2018" diff --git a/lib/dynasm-backend/README.md b/lib/singlepass-backend/README.md similarity index 68% rename from lib/dynasm-backend/README.md rename to lib/singlepass-backend/README.md index a525cbfac99..3d8c63615f5 100644 --- a/lib/dynasm-backend/README.md +++ b/lib/singlepass-backend/README.md @@ -14,18 +14,18 @@ Join the Wasmer Community - - Number of downloads from crates.io + + Number of downloads from crates.io - - Read our API documentation + + Read our API documentation

-# Wasmer dynasm backend +# Wasmer singlepass backend Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully compatible with Emscripten, Rust and Go. [Learn more](https://github.com/wasmerio/wasmer). -This crate represents the dynasm backend. +This crate represents the singlepass backend. diff --git a/lib/dynasm-backend/src/codegen.rs b/lib/singlepass-backend/src/codegen.rs similarity index 100% rename from lib/dynasm-backend/src/codegen.rs rename to lib/singlepass-backend/src/codegen.rs diff --git a/lib/dynasm-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs similarity index 100% rename from lib/dynasm-backend/src/codegen_x64.rs rename to lib/singlepass-backend/src/codegen_x64.rs diff --git a/lib/dynasm-backend/src/emitter_x64.rs b/lib/singlepass-backend/src/emitter_x64.rs similarity index 100% rename from lib/dynasm-backend/src/emitter_x64.rs rename to lib/singlepass-backend/src/emitter_x64.rs diff --git a/lib/dynasm-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs similarity index 90% rename from lib/dynasm-backend/src/lib.rs rename to lib/singlepass-backend/src/lib.rs index 0092b730268..cdb275cd3c0 100644 --- a/lib/dynasm-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -41,7 +41,7 @@ impl CacheGen for Placeholder { _module: &ModuleInner, ) -> Result<(Box, Box<[u8]>, Memory), CacheError> { Err(CacheError::Unknown( - "the dynasm backend doesn't support caching yet".to_string(), + "the singlepass backend doesn't support caching yet".to_string(), )) } } @@ -61,7 +61,7 @@ impl Compiler for SinglePassCompiler { _: Token, ) -> CompileResult { let mut mcg = codegen_x64::X64ModuleCodeGenerator::new(); - let info = parse::read_module(wasm, Backend::Dynasm, &mut mcg, &compiler_config)?; + let info = parse::read_module(wasm, Backend::Singlepass, &mut mcg, &compiler_config)?; let (ec, resolver) = mcg.finalize(&info)?; Ok(ModuleInner { cache_gen: Box::new(Placeholder), @@ -73,7 +73,7 @@ impl Compiler for SinglePassCompiler { unsafe fn from_cache(&self, _artifact: Artifact, _: Token) -> Result { Err(CacheError::Unknown( - "the dynasm backend doesn't support caching yet".to_string(), + "the singlepass backend doesn't support caching yet".to_string(), )) } } diff --git a/lib/dynasm-backend/src/machine.rs b/lib/singlepass-backend/src/machine.rs similarity index 100% rename from lib/dynasm-backend/src/machine.rs rename to lib/singlepass-backend/src/machine.rs diff --git a/lib/dynasm-backend/src/parse.rs b/lib/singlepass-backend/src/parse.rs similarity index 100% rename from lib/dynasm-backend/src/parse.rs rename to lib/singlepass-backend/src/parse.rs diff --git a/lib/dynasm-backend/src/protect_unix.rs b/lib/singlepass-backend/src/protect_unix.rs similarity index 100% rename from lib/dynasm-backend/src/protect_unix.rs rename to lib/singlepass-backend/src/protect_unix.rs diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 8dd8f83f492..d19fdab6d47 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -12,7 +12,7 @@ build = "build/mod.rs" wasmer-runtime-core = { path = "../runtime-core", version = "0.2.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.1.0", optional = true } -wasmer-dynasm-backend = { path = "../dynasm-backend", version = "0.1.0", optional = true } +wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.1.0", optional = true } [build-dependencies] wabt = "0.7.2" @@ -25,4 +25,4 @@ default = ["fast-tests"] fast-tests = [] clif = [] llvm = ["wasmer-llvm-backend"] -dynasm = ["wasmer-dynasm-backend"] \ No newline at end of file +singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/spectests/build/spectests.rs b/lib/spectests/build/spectests.rs index a13faefd18a..10fb4567851 100644 --- a/lib/spectests/build/spectests.rs +++ b/lib/spectests/build/spectests.rs @@ -107,13 +107,13 @@ fn get_compiler() -> impl Compiler { LLVMCompiler::new() } -#[cfg(feature = "dynasm")] +#[cfg(feature = "singlepass")] fn get_compiler() -> impl Compiler { - use wasmer_dynasm_backend::SinglePassCompiler; + use wasmer_singlepass_backend::SinglePassCompiler; SinglePassCompiler::new() } -#[cfg(not(any(feature = "llvm", feature = "clif", feature = "dynasm")))] +#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] fn get_compiler() -> impl Compiler { panic!("compiler not specified, activate a compiler via features"); use wasmer_clif_backend::CraneliftCompiler; diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index c61cdb18fc7..357adb5f70d 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -22,13 +22,13 @@ fn get_compiler() -> impl Compiler { LLVMCompiler::new() } -#[cfg(feature = "dynasm")] +#[cfg(feature = "singlepass")] fn get_compiler() -> impl Compiler { - use wasmer_dynasm_backend::SinglePassCompiler; + use wasmer_singlepass_backend::SinglePassCompiler; SinglePassCompiler::new() } -#[cfg(not(any(feature = "llvm", feature = "clif", feature = "dynasm")))] +#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))] fn get_compiler() -> impl Compiler { panic!("compiler not specified, activate a compiler via features"); use wasmer_clif_backend::CraneliftCompiler; diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 34550355805..d8ac1cbd780 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -6,14 +6,21 @@ use std::io; use std::io::Read; use std::path::PathBuf; use std::process::exit; +use std::str::FromStr; use hashbrown::HashMap; use structopt::StructOpt; use wasmer::webassembly::InstanceABI; use wasmer::*; +use wasmer_clif_backend::CraneliftCompiler; +use wasmer_llvm_backend::LLVMCompiler; use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}; -use wasmer_runtime_core::{self, backend::CompilerConfig}; +use wasmer_runtime_core::{ + self, + backend::{Compiler, CompilerConfig}, +}; +use wasmer_singlepass_backend::SinglePassCompiler; #[cfg(feature = "wasi")] use wasmer_wasi; @@ -62,13 +69,51 @@ struct Run { #[structopt(parse(from_os_str))] path: PathBuf, - /// Application arguments - #[structopt(name = "--", raw(multiple = "true"))] - args: Vec, + // Disable the cache + #[structopt( + long = "backend", + default_value = "cranelift", + raw(possible_values = "Backend::variants()", case_insensitive = "true") + )] + backend: Backend, /// Emscripten symbol map #[structopt(long = "em-symbol-map", parse(from_os_str))] em_symbol_map: Option, + + /// Application arguments + #[structopt(name = "--", raw(multiple = "true"))] + args: Vec, +} + +#[allow(dead_code)] +#[derive(Debug)] +enum Backend { + Cranelift, + Singlepass, + LLVM, +} + +impl Backend { + pub fn variants() -> &'static [&'static str] { + &["singlepass", "cranelift", "llvm"] + } +} + +impl FromStr for Backend { + type Err = String; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "singlepass" => Ok(Backend::Singlepass), + "cranelift" => Ok(Backend::Cranelift), + "llvm" => Ok(Backend::LLVM), + // "llvm" => Err( + // "The LLVM backend option is not enabled by default due to binary size constraints" + // .to_string(), + // ), + _ => Err(format!("The backend {} doesn't exist", s)), + } + } } #[derive(Debug, StructOpt)] @@ -177,6 +222,12 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .map_err(|e| format!("Can't convert from wast to wasm: {:?}", e))?; } + let compiler: Box = match options.backend { + Backend::Singlepass => Box::new(SinglePassCompiler::new()), + Backend::Cranelift => Box::new(CraneliftCompiler::new()), + Backend::LLVM => Box::new(LLVMCompiler::new()), + }; + let module = if !disable_cache { // If we have cache enabled @@ -202,11 +253,12 @@ fn execute_wasm(options: &Run) -> Result<(), String> { module } Err(_) => { - let module = webassembly::compile_with_config( + let module = webassembly::compile_with_config_with( &wasm_binary[..], CompilerConfig { symbol_map: em_symbol_map, }, + &*compiler, ) .map_err(|e| format!("Can't compile module: {:?}", e))?; // We try to save the module into a cache file @@ -217,11 +269,12 @@ fn execute_wasm(options: &Run) -> Result<(), String> { }; module } else { - webassembly::compile_with_config( + webassembly::compile_with_config_with( &wasm_binary[..], CompilerConfig { symbol_map: em_symbol_map, }, + &*compiler, ) .map_err(|e| format!("Can't compile module: {:?}", e))? }; diff --git a/src/webassembly.rs b/src/webassembly.rs index 01367795aed..fc32b3299a0 100644 --- a/src/webassembly.rs +++ b/src/webassembly.rs @@ -1,4 +1,5 @@ use std::panic; +pub use wasmer_runtime::compile_with_config_with; use wasmer_runtime::{ self as runtime, error::{CallResult, Result}, @@ -78,15 +79,15 @@ pub fn compile(buffer_source: &[u8]) -> Result { Ok(module) } -/// The same as `compile` but takes a `CompilerConfig` for the purpose of -/// changing the compiler's behavior -pub fn compile_with_config( - buffer_source: &[u8], - compiler_config: CompilerConfig, -) -> Result { - let module = runtime::compile_with_config(buffer_source, compiler_config)?; - Ok(module) -} +// /// The same as `compile` but takes a `CompilerConfig` for the purpose of +// /// changing the compiler's behavior +// pub fn compile_with_config_with( +// buffer_source: &[u8], +// compiler_config: CompilerConfig, +// ) -> Result { +// let module = runtime::compile_with_config(buffer_source, compiler_config)?; +// Ok(module) +// } /// Performs common instance operations needed when an instance is first run /// including data setup, handling arguments and calling a main function