Skip to content

Commit

Permalink
Merge #276
Browse files Browse the repository at this point in the history
276: Single-pass native code generation for x86-64 using dynasm. r=losfair a=losfair



Co-authored-by: losfair <[email protected]>
  • Loading branch information
bors[bot] and losfair committed Mar 21, 2019
2 parents 40be4da + 08ba696 commit 758ccc6
Show file tree
Hide file tree
Showing 39 changed files with 6,877 additions and 74 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
- run:
name: Install lint deps
command: |
git config --global --unset url."ssh://[email protected]".insteadOf || true
rustup toolchain install nightly
rustup component add rustfmt
rustup component add clippy
rustup component add clippy --toolchain=nightly || cargo +nightly install --git https://github.com/rust-lang/rust-clippy/ --force clippy
- run:
name: Execute lints
command: |
Expand Down Expand Up @@ -274,6 +276,9 @@ jobs:
- 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-emscripten
make test-emscripten-nightly
- save_cache:
paths:
- /usr/local/cargo/registry
Expand Down
68 changes: 68 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-runtime = { path = "lib/runtime" }
wasmer-runtime-core = { path = "lib/runtime-core" }
wasmer-emscripten = { path = "lib/emscripten" }

[target.'cfg(not(windows))'.dependencies]
wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true }

[workspace]
members = ["lib/clif-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"]
members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"]

[build-dependencies]
wabt = "0.7.2"
Expand All @@ -42,3 +41,4 @@ default = ["fast-tests"]
# This feature will allow cargo test to run much faster
fast-tests = []
llvm = ["wasmer-llvm-backend"]
dynasm = ["wasmer-dynasm-backend"]
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,29 @@ integration-tests: release

lint:
cargo fmt --all -- --check
cargo clippy --all
cargo +nightly clippy --all

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 -- $(runargs)
cargo test --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests --exclude wasmer-dynasm-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-emscripten:
cargo test --manifest-path lib/emscripten/Cargo.toml --features clif -- --test-threads=1 $(runargs)
cargo test --manifest-path lib/emscripten/Cargo.toml --features llvm -- --test-threads=1 $(runargs)

test-emscripten-nightly:
cargo test --manifest-path lib/emscripten/Cargo.toml --features dynasm -- --test-threads=1 $(runargs)

release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows
# brew install mingw-w64
Expand Down
37 changes: 37 additions & 0 deletions examples/single_pass_tests/br_table.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(module
(func $main (export "main")
(i32.eq (call $test (i32.const 0)) (i32.const 2))
(i32.eq (call $test (i32.const 1)) (i32.const 0))
(i32.eq (call $test (i32.const 2)) (i32.const 1))
(i32.eq (call $test (i32.const 3)) (i32.const 3))
(i32.eq (call $test (i32.const 4)) (i32.const 3))
(i32.and)
(i32.and)
(i32.and)
(i32.and)
(i32.const 1)
(i32.eq)
(br_if 0)
(unreachable)
)

(func $test (param $p i32) (result i32)
(block
(block
(block
(block
(block
(get_local $p)
(br_table 2 0 1 3)
)
(return (i32.const 0))
)
(return (i32.const 1))
)
(return (i32.const 2))
)
(return (i32.const 3))
)
(unreachable)
)
)
23 changes: 23 additions & 0 deletions examples/single_pass_tests/call.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(module
(func $main (export "main")
(local $a i32)
(block
(set_local $a (i32.const 33))
(i32.const 11)
(call $foo (get_local $a))
(i32.add)
(i32.const 86)
(i32.eq)
(br_if 0)
(unreachable)
)
)

(func $foo (param $input i32) (result i32)
(local $a i32)
(set_local $a (i32.const 42))
(get_local $a)
(get_local $input)
(i32.add)
)
)
25 changes: 25 additions & 0 deletions examples/single_pass_tests/call_indirect.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(module
(type $binop (func (param i32 i32) (result i32)))
(table 1 100 anyfunc)
(elem (i32.const 5) $sub)
(elem (i32.const 10) $add)

(func $main (export "main")
(if (i32.eq (call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 10)) (i32.const 43))
(then)
(else unreachable)
)
(if (i32.eq (call_indirect (type $binop) (i32.const 42) (i32.const 1) (i32.const 5)) (i32.const 41))
(then)
(else unreachable)
)
)

(func $add (param i32) (param i32) (result i32)
(i32.add (get_local 0) (get_local 1))
)

(func $sub (param i32) (param i32) (result i32)
(i32.sub (get_local 0) (get_local 1))
)
)
36 changes: 36 additions & 0 deletions examples/single_pass_tests/div.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(module
(func $main (export "main")
(i32.const 1)
(if (i32.ne (i32.div_s (i32.const 2) (i32.const -1)) (i32.const -2))
(then unreachable)
)
(i32.const 2)
(if (i32.ne (i32.div_u (i32.const 2) (i32.const -1)) (i32.const 0))
(then unreachable)
)
(i32.const 3)
(if (i32.ne (i32.div_u (i32.const 10) (i32.const 5)) (i32.const 2))
(then unreachable)
)
(i32.const 4)
(if (i64.ne (i64.div_s (i64.const 300000000000) (i64.const -1)) (i64.const -300000000000))
(then unreachable)
)
(i32.const 5)
(if (i64.ne (i64.div_u (i64.const 300000000000) (i64.const -1)) (i64.const 0))
(then unreachable)
)
(i32.const 6)
(if (i64.ne (i64.div_u (i64.const 300000000000) (i64.const 2)) (i64.const 150000000000))
(then unreachable)
)
(i32.add)
(i32.add)
(i32.add)
(i32.add)
(i32.add)
(if (i32.ne (i32.const 21))
(then unreachable)
)
)
)
26 changes: 26 additions & 0 deletions examples/single_pass_tests/global.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(module
(global $g1 (mut i32) (i32.const 0))
(global $g2 (mut i32) (i32.const 99))
(func $main (export "main")
(if (i32.eq (get_global $g1) (i32.const 0))
(then)
(else unreachable)
)
(if (i32.eq (get_global $g2) (i32.const 99))
(then)
(else unreachable)
)

(set_global $g1 (i32.add (get_global $g1) (i32.const 1)))
(set_global $g2 (i32.sub (get_global $g2) (i32.const 1)))

(if (i32.eq (get_global $g1) (i32.const 1))
(then)
(else unreachable)
)
(if (i32.eq (get_global $g2) (i32.const 98))
(then)
(else unreachable)
)
)
)
Loading

0 comments on commit 758ccc6

Please sign in to comment.