diff --git a/README.md b/README.md index 3b398178e..d9dac5216 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ If you want to add new keywords, you'll need to install [gperf](https://www.gnu.org/software/gperf/). Before you upload your PR, please run `make update-gperf` to update the prebuilt C++ sources in `src/prebuilt/`. -## Running wat2wasm and wast2json +## Running wat2wasm Some examples: @@ -198,10 +198,6 @@ $ 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 - -# parse spec-test.wast, and write files to spec-test.json. Modules are written -# to spec-test.0.wasm, spec-test.1.wasm, etc. -$ bin/wast2json spec-test.wast -o spec-test.json ``` You can use `--help` to get additional help: @@ -260,6 +256,10 @@ You can use `--help` to get additional help: $ bin/wasm-interp --help ``` +## Running wast2json + +See [wast2json.md](docs/wast2json.md). + ## Running wasm-decompile For example: diff --git a/docs/wast2json.md b/docs/wast2json.md new file mode 100644 index 000000000..efd7f853a --- /dev/null +++ b/docs/wast2json.md @@ -0,0 +1,566 @@ +# wast2json + +`wast2json` converts a `.wast` file to a `.json` file, and a collection of +associated `.wat` file and `.wasm` files. + +## Example + +```sh +# parse spec-test.wast, and write files to spec-test.json. Modules are written +# to spec-test.0.wasm, spec-test.1.wasm, etc. +$ bin/wast2json spec-test.wast -o spec-test.json +``` + +## Wast + +The wast format is described in the [spec +interpreter](https://github.com/WebAssembly/spec/tree/master/interpreter#scripts). +It is an extension of the `.wat` text format, with additional commands for +running scripts. The syntax is repeated here: + +``` +script: * + +cmd: + ;; define, validate, and initialize module + ( register ? ) ;; register module for imports +module with given failure string + ;; perform action and print results + ;; assert result of an action + ;; meta command + +module: + ... + ( module ? binary * ) ;; module in binary format (may be malformed) + ( module ? quote * ) ;; module quoted in text (may be malformed) + +action: + ( invoke ? * ) ;; invoke function export + ( get ? ) ;; get global export + +assertion: + ( assert_return * ) ;; assert action has expected results + ( assert_trap ) ;; assert action traps with given failure string + ( assert_exhaustion ) ;; assert action exhausts system resources + ( assert_malformed ) ;; assert module cannot be decoded with given failure string + ( assert_invalid ) ;; assert module is invalid with given failure string + ( assert_unlinkable ) ;; assert module fails to link + ( assert_trap ) ;; assert module traps on instantiation + +result: + ( .const ) + +numpat: + ;; literal result + nan:canonical ;; NaN in canonical form + nan:arithmetic ;; NaN with 1 in MSB of payload + +meta: + ( script ?