Albert@Mar 2018
WebAssembly is a binary instruction format for a stack-based virtual
machine. WebAssembly is designed as a portable target for
compilation of high-level languages like C/C++/Rust, enabling
deployment on the web for client and server applications.
Define a portable, size- and load-time-efficient binary format to serve
as a compilation target which can be compiled to execute at native
speed by taking advantage of common hardware capabilities available
on a wide range of platforms, including mobile and IoT.
Parse
Compiling + optimizing
Re-optimize
Execut
https://webassembly.org/docs/binary-encoding/#why-a-binary-encoding-instead-of-a-
text-only-representation
https://webassembly.org/docs/use-cases/
Emen
source.c -----> target.js
Emen (with flag)
source.c -----> target.wasm
Binaryen WABT
math.js ---> math.wast ---> math.wasm
linear assembly
bytecode
Chrome: 打开 chrome://flags/#enable-webassemblyenable
C/C++ >> WebAssembly
emcc math.c -Os -s WASM=1 -s SIDE_MODULE=1 -o math.wasm
C/C++ >> WebAssembly
C/C++ >> WebAssembly
C/C++ >> WASM
asm.js >> WASM
Binaryen WABT
math.js ---> math.wast ---> math.wasm
asm2wasm math.js -o math.wast
wast2wasm math.wast -o math.wasm
asm.js >> WASM
Binaryen WABT
math.js ---> math.wast ---> math.wasm
asm2wasm math.js -o math.wast
wast2wasm math.wast -o math.wasm
WASM + exit.js
WASM + exit.js
WASM + exit.js
WASM + exit.js
new WebAssembly.Table(
More Examples
Events.emit(Thanks’)
&&
console.log(‘End’);