• Stars
    star
    6,778
  • Rank 5,827 (Top 0.2 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The WebAssembly Binary Toolkit

Github CI Status

WABT: The WebAssembly Binary Toolkit

WABT (we pronounce it "wabbit") is a suite of tools for WebAssembly, including:

  • wat2wasm: translate from WebAssembly text format to the WebAssembly binary format
  • wasm2wat: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
  • wasm-objdump: print information about a wasm binary. Similiar to objdump.
  • wasm-interp: decode and run a WebAssembly binary file using a stack-based interpreter
  • wasm-decompile: decompile a wasm binary into readable C-like syntax.
  • wat-desugar: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
  • wasm2c: convert a WebAssembly binary file to a C source and header
  • wasm-strip: remove sections of a WebAssembly binary file
  • wasm-validate: validate a file in the WebAssembly binary format
  • wast2json: convert a file in the wasm spec test format to a JSON file and associated wasm binary files
  • wasm-opcodecnt: count opcode usage for instructions
  • spectest-interp: read a Spectest JSON file, and run its tests in the interpreter

These tools are intended for use in (or for development of) toolchains or other systems that want to manipulate WebAssembly files. Unlike the WebAssembly spec interpreter (which is written to be as simple, declarative and "speccy" as possible), they are written in C/C++ and designed for easier integration into other systems. Unlike Binaryen these tools do not aim to provide an optimization platform or a higher-level compiler target; instead they aim for full fidelity and compliance with the spec (e.g. 1:1 round-trips with no changes to instructions).

Online Demos

Wabt has been compiled to JavaScript via emscripten. Some of the functionality is available in the following demos:

Supported Proposals

  • Proposal: Name and link to the WebAssembly proposal repo
  • flag: Flag to pass to the tool to enable/disable support for the feature
  • default: Whether the feature is enabled by default
  • binary: Whether wabt can read/write the binary format
  • text: Whether wabt can read/write the text format
  • validate: Whether wabt can validate the syntax
  • interpret: Whether wabt can execute these operations in wasm-interp or spectest-interp
  • wasm2c: Whether wasm2c supports these operations
Proposal flag default binary text validate interpret wasm2c
exception handling --enable-exceptions βœ“ βœ“ βœ“ βœ“ βœ“
mutable globals --disable-mutable-globals βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
nontrapping float-to-int conversions --disable-saturating-float-to-int βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
sign extension --disable-sign-extension βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
simd --disable-simd βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
threads --enable-threads βœ“ βœ“ βœ“ βœ“
multi-value --disable-multi-value βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
tail-call --enable-tail-call βœ“ βœ“ βœ“ βœ“
bulk memory --disable-bulk-memory βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
reference types --disable-reference-types βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
annotations --enable-annotations βœ“
memory64 --enable-memory64 βœ“ βœ“ βœ“ βœ“ βœ“
multi-memory --enable-multi-memory βœ“ βœ“ βœ“ βœ“ βœ“
extended-const --enable-extended-const βœ“ βœ“ βœ“ βœ“ βœ“
relaxed-simd --enable-relaxed-simd βœ“ βœ“ βœ“ βœ“

Cloning

Clone as normal, but don't forget to get the submodules as well:

$ git clone --recursive https://github.com/WebAssembly/wabt
$ cd wabt
$ git submodule update --init

This will fetch the testsuite and gtest repos, which are needed for some tests.

Building using CMake directly (Linux and macOS)

You'll need CMake. You can then run CMake, the normal way:

$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

This will produce build files using CMake's default build generator. Read the CMake documentation for more information.

NOTE: You must create a separate directory for the build artifacts (e.g. build above). Running cmake from the repo root directory will not work since the build produces an executable called wasm2c which conflicts with the wasm2c directory.

Building using the top-level Makefile (Linux and macOS)

NOTE: Under the hood, this uses make to run CMake, which then calls ninja to perform that actual build. On some systems (typically macOS), this doesn't build properly. If you see these errors, you can build using CMake directly as described above.

You'll need CMake and Ninja. If you just run make, it will run CMake for you, and put the result in out/clang/Debug/ by default:

Note: If you are on macOS, you will need to use CMake version 3.2 or higher

$ make

This will build the default version of the tools: a debug build using the Clang compiler.

There are many make targets available for other configurations as well. They are generated from every combination of a compiler, build type and configuration.

  • compilers: gcc, clang, gcc-i686, emscripten
  • build types: debug, release
  • configurations: empty, asan, msan, lsan, ubsan, fuzz, no-tests

They are combined with dashes, for example:

$ make clang-debug
$ make gcc-i686-release
$ make clang-debug-lsan
$ make gcc-debug-no-tests

Building (Windows)

You'll need CMake. You'll also need Visual Studio (2015 or newer) or MinGW.

Note: Visual Studio 2017 and later come with CMake (and the Ninja build system) out of the box, and should be on your PATH if you open a Developer Command prompt. See https://aka.ms/cmake for more details.

You can run CMake from the command prompt, or use the CMake GUI tool. See Running CMake for more information.

When running from the commandline, create a new directory for the build artifacts, then run cmake from this directory:

> cd [build dir]
> cmake [wabt project root] -DCMAKE_BUILD_TYPE=[config] -DCMAKE_INSTALL_PREFIX=[install directory] -G [generator]

The [config] parameter should be a CMake build type, typically DEBUG or RELEASE.

The [generator] parameter should be the type of project you want to generate, for example "Visual Studio 14 2015". You can see the list of available generators by running cmake --help.

To build the project, you can use Visual Studio, or you can tell CMake to do it:

> cmake --build [wabt project root] --config [config] --target install

This will build and install to the installation directory you provided above.

So, for example, if you want to build the debug configuration on Visual Studio 2015:

> mkdir build
> cd build
> cmake .. -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=..\ -G "Visual Studio 14 2015"
> cmake --build . --config DEBUG --target install

Adding new keywords to the lexer

If you want to add new keywords, you'll need to install gperf. Before you upload your PR, please run make update-gperf to update the prebuilt C++ sources in src/prebuilt/.

Running wat2wasm

Some examples:

# parse test.wat and write to .wasm binary file with the same name
$ bin/wat2wasm test.wat

# parse test.wat and write to binary file test.wasm
$ bin/wat2wasm test.wat -o test.wasm

# parse spec-test.wast, and write verbose output to stdout (including the
# meaning of every byte)
$ bin/wat2wasm spec-test.wast -v

You can use --help to get additional help:

$ bin/wat2wasm --help

Or try the online demo.

Running wasm2wat

Some examples:

# parse binary file test.wasm and write text file test.wat
$ bin/wasm2wat test.wasm -o test.wat

# parse test.wasm and write test.wat
$ bin/wasm2wat test.wasm -o test.wat

You can use --help to get additional help:

$ bin/wasm2wat --help

Or try the online demo.

Running wasm-interp

Some examples:

# parse binary file test.wasm, and type-check it
$ bin/wasm-interp test.wasm

# parse test.wasm and run all its exported functions
$ bin/wasm-interp test.wasm --run-all-exports

# parse test.wasm, run the exported functions and trace the output
$ bin/wasm-interp test.wasm --run-all-exports --trace

# parse test.json and run the spec tests
$ bin/wasm-interp test.json --spec

# parse test.wasm and run all its exported functions, setting the value stack
# size to 100 elements
$ bin/wasm-interp test.wasm -V 100 --run-all-exports

You can use --help to get additional help:

$ bin/wasm-interp --help

Running wast2json

See wast2json.md.

Running wasm-decompile

For example:

# parse binary file test.wasm and write text file test.dcmp
$ bin/wasm-decompile test.wasm -o test.dcmp

You can use --help to get additional help:

$ bin/wasm-decompile --help

See decompiler.md for more information on the language being generated.

Running wasm2c

See wasm2c.md

Running the test suite

See test/README.md.

Sanitizers

To build with the LLVM sanitizers, append the sanitizer name to the target:

$ make clang-debug-asan
$ make clang-debug-msan
$ make clang-debug-lsan
$ make clang-debug-ubsan

There are configurations for the Address Sanitizer (ASAN), Memory Sanitizer (MSAN), Leak Sanitizer (LSAN) and Undefined Behavior Sanitizer (UBSAN). You can read about the behaviors of the sanitizers in the link above, but essentially the Address Sanitizer finds invalid memory accesses (use after free, access out-of-bounds, etc.), Memory Sanitizer finds uses of uninitialized memory, the Leak Sanitizer finds memory leaks, and the Undefined Behavior Sanitizer finds undefined behavior (surprise!).

Typically, you'll just want to run all the tests for a given sanitizer:

$ make test-asan

You can also run the tests for a release build:

$ make test-clang-release-asan
...

The GitHub actions bots run all of these tests (and more). Before you land a change, you should run them too. One easy way is to use the test-everything target:

$ make test-everything

Fuzzing

To build using the LLVM fuzzer support, append fuzz to the target:

$ make clang-debug-fuzz

This will produce a wasm2wat_fuzz binary. It can be used to fuzz the binary reader, as well as reproduce fuzzer errors found by oss-fuzz.

$ out/clang/Debug/fuzz/wasm2wat_fuzz ...

See the libFuzzer documentation for more information about how to use this tool.

More Repositories

1

design

WebAssembly Design Documents
11,261
star
2

binaryen

Optimizer and compiler/toolchain library for WebAssembly
WebAssembly
7,376
star
3

WASI

WebAssembly System Interface
Rust
4,810
star
4

spec

WebAssembly specification, reference interpreter, and test suite.
WebAssembly
3,148
star
5

wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain
CMake
1,224
star
6

gc

Branch of the spec repo scoped to discussion of GC integration in WebAssembly
WebAssembly
982
star
7

component-model

Repository for design and specification of the Component Model
Python
945
star
8

proposals

Tracking WebAssembly proposals
849
star
9

wasi-libc

WASI libc implementation for WebAssembly
C
836
star
10

interface-types

WebAssembly
641
star
11

threads

Threads and Atomics in WebAssembly
WebAssembly
577
star
12

wasm-c-api

Wasm C API prototype
C++
539
star
13

simd

Branch of the spec repo scoped to discussion of SIMD in WebAssembly
WebAssembly
531
star
14

meetings

WebAssembly meetings (VC or in-person), agendas, and notes
HTML
468
star
15

wasi-nn

Neural Network proposal for WASI
449
star
16

esm-integration

ECMAScript module integration
WebAssembly
370
star
17

wasm-jit-prototype

Standalone VM using LLVM JIT
C++
309
star
18

tool-conventions

Conventions supporting interoperatibility between tools working with WebAssembly.
297
star
19

website

WebAssembly website
CSS
270
star
20

memory64

Memory with 64-bit indexes
WebAssembly
210
star
21

testsuite

Mirror of the spec testsuite
WebAssembly
191
star
22

wasi-filesystem

Filesystem API for WASI
167
star
23

reference-types

Proposal for adding basic reference types (anyref)
WebAssembly
163
star
24

wasi-crypto

WASI Cryptography API Proposal
Makefile
162
star
25

exception-handling

Proposal to add exception handling to WebAssembly
WebAssembly
156
star
26

wasi-sockets

WASI API proposal for managing sockets
Rust
155
star
27

wasi-http

142
star
28

wasi-threads

WebAssembly
136
star
29

wasi-io

I/O Types proposal for WASI
132
star
30

multi-memory

Multiple per-module memories for Wasm
WebAssembly
127
star
31

stack-switching

A repository for the stack switching proposal.
WebAssembly
124
star
32

module-linking

Proposal for allowing modules to define, import and export modules and instances
WebAssembly
120
star
33

tail-call

Proposal to add tail calls to WebAssembly
WebAssembly
110
star
34

wasp

WebAssembly module decoder in C++
C++
106
star
35

function-references

Proposal for Typed Function References
WebAssembly
99
star
36

debugging

Design documents and discussions about debug support in WebAssembly
98
star
37

wasmint

Library for interpreting / debugging wasm code
C++
94
star
38

bulk-memory-operations

Bulk memory operations
WebAssembly
74
star
39

wasi-webgpu

72
star
40

js-promise-integration

JavaScript Promise Integration
WebAssembly
69
star
41

multi-value

Proposal to add multi-values to WebAssembly
WebAssembly
66
star
42

wasi-testsuite

WASI Testsuite
Rust
51
star
43

wasi-cloud-core

Rust
50
star
44

flexible-vectors

Vector operations for WebAssembly
WebAssembly
48
star
45

waterfall

Build and test bots
45
star
46

js-types

Proposal for adding type reflection to the JS API
WebAssembly
44
star
47

relaxed-simd

Relax the strict determinism requirements of SIMD operations.
WebAssembly
43
star
48

content-security-policy

WebAssembly
38
star
49

shared-everything-threads

A draft proposal for spawning threads in WebAssembly
WebAssembly
38
star
50

stringref

WebAssembly
37
star
51

JS-BigInt-integration

JavaScript BigInt to WebAssembly i64 integration
WebAssembly
36
star
52

wasi-keyvalue

35
star
53

wasi-libc-old

Precursor to WASI libc.
C
35
star
54

wasi-clocks

Clocks API for WASI
35
star
55

wasi-random

Entropy source API for WASI
29
star
56

benchmarks

Resources for collaborative benchmarking
JavaScript
27
star
57

wasi-sql

25
star
58

wasi-sql-embed

23
star
59

memory-control

A proposal to introduce finer grained control of WebAssembly memory.
WebAssembly
21
star
60

annotations

Proposal for Custom Annotation Syntax in the Text Format
WebAssembly
20
star
61

proposal-type-imports

Proposal for Type Imports & Exports
WebAssembly
20
star
62

constant-time

Constant-time WebAssembly
WebAssembly
20
star
63

wasi-proposal-template

Starter template for proposing a new WASI API
19
star
64

wasi-messaging

Messaging proposal for WASI
18
star
65

wasi-tools

WASI tools
Rust
17
star
66

funclets

Proposal for adding funclets - flexible intraprocedural control flow
WebAssembly
17
star
67

wasi-parallel

wasi-parallel is a proposal to add a parallel for construct to WASI.
Shell
17
star
68

sign-extension-ops

Sign-extension opcodes
WebAssembly
17
star
69

mutable-global

Import & export of mutable globals
WebAssembly
16
star
70

wasi-poll

16
star
71

wasi-cli

Command-Line Interface (CLI) World for WASI
15
star
72

extended-const

Proposal for extended constant expressions
WebAssembly
15
star
73

wasi-observe

Observability World for WASI
Just
15
star
74

instrument-tracing

Proposal to add instrumentation and tracing instructions to WebAssembly
WebAssembly
14
star
75

nontrapping-float-to-int-conversions

Proposal to add non-trapping float-to-int conversions to WebAssembly
WebAssembly
14
star
76

wasi-blobstore

14
star
77

conditional-sections

WebAssembly
13
star
78

wasi-grpc

13
star
79

profiles

Profiles proposal
WebAssembly
12
star
80

wasi-logging

WASI logging API
11
star
81

wasi-i2c

I2C API for WASI
Rust
11
star
82

extended-name-section

WebAssembly
11
star
83

feature-detection

WebAssembly
10
star
84

wasi-config

10
star
85

webassembly.github.io

Redirect to webassembly.org
HTML
10
star
86

testsuite-js

WebAssembly testsuite tests converted to single-file JavaScript tests
JavaScript
9
star
87

lld

Staging repository for upstreaming WebAssembly support into lld
C++
9
star
88

branch-hinting

Proposal to add branch hinting functionality to WebAssembly
WebAssembly
9
star
89

decompressor-prototype

C++
8
star
90

wat-numeric-values

Proposal to add numeric values to data segment definitions in the text format
WebAssembly
7
star
91

gc-js-customization

WebAssembly
7
star
92

js-string-builtins

JS String Builtins
WebAssembly
6
star
93

wasi-classic-command

6
star
94

wasi-url

6
star
95

half-precision

Proposal to introduce half precision operations
WebAssembly
6
star
96

wit-abi-up-to-date

5
star
97

wasi-spi

Rust
5
star
98

wg-charter

Proposed WebAssembly Working Group charter
HTML
5
star
99

call-tags

WebAssembly
4
star
100

cg-charter

Proposed WebAssembly Community Group charter
HTML
4
star