Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ bin/wasm-shell
bin/wasm-opt
bin/asm2wasm
bin/wasm2asm
bin/s2wasm
bin/wasm-as
bin/wasm-dis
lib/
Expand Down
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,6 @@ SET_PROPERTY(TARGET wasm2asm PROPERTY CXX_STANDARD 11)
SET_PROPERTY(TARGET wasm2asm PROPERTY CXX_STANDARD_REQUIRED ON)
INSTALL(TARGETS wasm2asm DESTINATION ${CMAKE_INSTALL_BINDIR})

SET(s2wasm_SOURCES
src/tools/s2wasm.cpp
src/wasm-linker.cpp
)
ADD_EXECUTABLE(s2wasm
${s2wasm_SOURCES})
TARGET_LINK_LIBRARIES(s2wasm passes wasm asmjs ir cfg support)
SET_PROPERTY(TARGET s2wasm PROPERTY CXX_STANDARD 11)
SET_PROPERTY(TARGET s2wasm PROPERTY CXX_STANDARD_REQUIRED ON)
INSTALL(TARGETS s2wasm DESTINATION ${CMAKE_INSTALL_BINDIR})

SET(wasm-emscripten-finalize_SOURCES
src/tools/wasm-emscripten-finalize.cpp
)
Expand Down
32 changes: 1 addition & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Binaryen is a compiler and toolchain infrastructure library for WebAssembly, wri
Compilers built using Binaryen include

* [`asm2wasm`](https://github.com/WebAssembly/binaryen/blob/master/src/asm2wasm.h) which compiles asm.js to WebAssembly
* [`s2wasm`](https://github.com/WebAssembly/binaryen/blob/master/src/s2wasm.h) which compiles the LLVM WebAssembly's backend `.s` output format
* [`AssemblyScript`](https://github.com/AssemblyScript/assemblyscript) which compiles TypeScript to Binaryen IR
* [`wasm2asm`](https://github.com/WebAssembly/binaryen/blob/master/src/wasm2asm.h) which compiles WebAssembly to asm.js
* [`mir2wasm`](https://github.com/brson/mir2wasm/) which compiles Rust MIR
Expand Down Expand Up @@ -64,9 +63,9 @@ This repository contains code that builds the following tools in `bin/`:
* **wasm-opt**: Loads WebAssembly and runs Binaryen IR passes on it.
* **asm2wasm**: An asm.js-to-WebAssembly compiler, using Emscripten's asm optimizer infrastructure. This is used by Emscripten in Binaryen mode when it uses Emscripten's fastcomp asm.js backend.
* **wasm2asm**: A WebAssembly-to-asm.js compiler (still experimental).
* **s2wasm**: A compiler from the `.s` format emitted by the new WebAssembly backend being developed in LLVM. This is used by Emscripten in Binaryen mode when it integrates with the new LLVM backend.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we update this list, maybe worth adding wasm-emscripten-finalize and wasm-link-metadata?

* **wasm-merge**: Combines wasm files into a single big wasm file (without sophisticated linking).
* **wasm-ctor-eval**: A tool that can execute C++ global constructors ahead of time. Used by Emscripten.
* **wasm-emscripten-finalize**: Takes a wasm binary produced by llvm+lld and performs emscripten-specific passes over it.
* **wasm.js**: wasm.js contains Binaryen components compiled to JavaScript, including the interpreter, `asm2wasm`, the S-Expression parser, etc., which allow you to use Binaryen with Emscripten and execute code compiled to WASM even if the browser doesn't have native support yet. This can be useful as a (slow) polyfill.
* **binaryen.js**: A standalone JavaScript library that exposes Binaryen methods for [creating and optimizing WASM modules](https://github.com/WebAssembly/binaryen/blob/master/test/binaryen.js/hello-world.js).

Expand Down Expand Up @@ -179,31 +178,6 @@ Pass `--debug` on the command line to see debug info, about asm.js functions as

When using `emcc` with the `BINARYEN` option, it will use Binaryen to build to WebAssembly. This lets you compile C and C++ to WebAssembly, with emscripten using asm.js internally as a build step. Since emscripten's asm.js generation is very stable, and asm2wasm is a fairly simple process, this method of compiling C and C++ to WebAssembly is usable already. See the [emscripten wiki](https://github.com/kripken/emscripten/wiki/WebAssembly) for more details about how to use it.

### C/C++ Source ⇒ WebAssembly LLVM backend ⇒ s2wasm ⇒ WebAssembly

Binaryen's `s2wasm` tool can translate the `.s` output from the LLVM WebAssembly backend into WebAssembly. You can receive `.s` output from `llc`, and then run `s2wasm` on that:

```
llc code.ll -mtriple=wasm32-unknown-unknown-elf -filetype=asm -o code.s
s2wasm code.s > code.wat
```

You can also use Emscripten, which will do those steps for you (as well as link to system libraries, etc.). You can use either normal Emscripten, including it's "fastcomp" fork of LLVM, or you can use "vanilla" LLVM, that is, pure upstream LLVM without Emscripten's additions. With Vanilla LLVM, you can build with

```
./emcc input.cpp -s BINARYEN=1
```

With normal Emscripten, you will need to tell it to use the WebAssembly backend, since its default is asm.js, by setting an env var,

```
EMCC_WASM_BACKEND=1 ./emcc input.cpp -s BINARYEN=1
```

(without the env var, the `BINARYEN` option will make it use the asm.js backend, then `asm2wasm`).

For more details, see the [emscripten wiki](https://github.com/kripken/emscripten/wiki/WebAssembly).

## Testing

```
Expand All @@ -212,10 +186,6 @@ For more details, see the [emscripten wiki](https://github.com/kripken/emscripte

(or `python check.py`) will run `wasm-shell`, `wasm-opt`, `asm2wasm`, `wasm.js`, etc. on the testcases in `test/`, and verify their outputs.

It will also run `s2wasm` through the last known good LLVM output from the [build waterfall][].

[build waterfall]: https://build.chromium.org/p/client.wasm.llvm/console

The `check.py` script supports some options:

```
Expand Down
32 changes: 1 addition & 31 deletions auto_update_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from scripts.test.support import run_command, split_wast, node_test_glue, node_has_webassembly
from scripts.test.shared import (
ASM2WASM, MOZJS, NODEJS, S2WASM, WASM_OPT, WASM_AS, WASM_DIS,
ASM2WASM, MOZJS, NODEJS, WASM_OPT, WASM_AS, WASM_DIS,
WASM_CTOR_EVAL, WASM_MERGE, WASM_REDUCE, WASM2ASM, WASM_METADCE,
WASM_EMSCRIPTEN_FINALIZE, BINARYEN_INSTALL_DIR,
files_with_pattern, has_shell_timeout)
Expand Down Expand Up @@ -69,35 +69,6 @@ def update_asm_js_tests():
run_command(cmd)


def update_dot_s_tests():
extension_arg_map = {
'.wast': [],
'.clamp.wast': ['--trap-mode=clamp'],
'.js.wast': ['--trap-mode=js'],
'.jscall.wast': ['--emscripten-reserved-function-pointers=3'],
}
for dot_s_dir in ['dot_s', 'llvm_autogenerated']:
for s in sorted(os.listdir(os.path.join('test', dot_s_dir))):
if not s.endswith('.s'):
continue
print '..', s
for ext, ext_args in extension_arg_map.iteritems():
wasm = s.replace('.s', ext)
expected_file = os.path.join('test', dot_s_dir, wasm)
if ext != '.wast' and not os.path.exists(expected_file):
continue

full = os.path.join('test', dot_s_dir, s)
stack_alloc = ['--allocate-stack=1024'] if dot_s_dir == 'llvm_autogenerated' else []
cmd = S2WASM + [full, '--emscripten-glue'] + stack_alloc + ext_args
if s.startswith('start_'):
cmd.append('--start')
actual = run_command(cmd, stderr=subprocess.PIPE, expected_err='')

with open(expected_file, 'w') as o:
o.write(actual)


def update_lld_tests():
print '\n[ checking wasm-emscripten-finalize testcases... ]\n'

Expand Down Expand Up @@ -435,7 +406,6 @@ def update_reduce_tests():

def main():
update_asm_js_tests()
update_dot_s_tests()
update_lld_tests()
update_wasm_opt_tests()
update_bin_fmt_tests()
Expand Down
3 changes: 0 additions & 3 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import scripts.test.asm2wasm as asm2wasm
import scripts.test.lld as lld
import scripts.test.s2wasm as s2wasm
import scripts.test.wasm2asm as wasm2asm

if options.interpreter:
Expand Down Expand Up @@ -632,8 +631,6 @@ def main():

run_spec_tests()
run_binaryen_js_tests()
s2wasm.test_s2wasm()
s2wasm.test_linker()
lld.test_wasm_emscripten_finalize()
wasm2asm.test_wasm2asm()
run_validator_tests()
Expand Down
134 changes: 0 additions & 134 deletions scripts/test/s2wasm.py

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def is_exe(fpath):
WASM_CTOR_EVAL = [os.path.join(options.binaryen_bin, 'wasm-ctor-eval')]
WASM_SHELL = [os.path.join(options.binaryen_bin, 'wasm-shell')]
WASM_MERGE = [os.path.join(options.binaryen_bin, 'wasm-merge')]
S2WASM = [os.path.join(options.binaryen_bin, 's2wasm')]
WASM_REDUCE = [os.path.join(options.binaryen_bin, 'wasm-reduce')]
WASM_METADCE = [os.path.join(options.binaryen_bin, 'wasm-metadce')]
WASM_EMSCRIPTEN_FINALIZE = [os.path.join(options.binaryen_bin,
Expand All @@ -192,7 +191,6 @@ def wrap_with_valgrind(cmd):
WASM_DIS = wrap_with_valgrind(WASM_DIS)
ASM2WASM = wrap_with_valgrind(ASM2WASM)
WASM_SHELL = wrap_with_valgrind(WASM_SHELL)
S2WASM = wrap_with_valgrind(S2WASM)

os.environ['BINARYEN'] = os.getcwd()

Expand Down
Loading