diff options
61 files changed, 346 insertions, 192 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 199a276a..4c185d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,8 +272,11 @@ if (NOT EMSCRIPTEN) ) endfunction() - # wast2wasm - wabt_executable(wast2wasm src/tools/wast2wasm.cc) + # wat2wasm + wabt_executable(wat2wasm src/tools/wat2wasm.cc) + + # wast2json + wabt_executable(wast2json src/tools/wast2json.cc) # wasm2wat wabt_executable(wasm2wat src/tools/wasm2wat.cc) @@ -4,8 +4,8 @@ WABT (we pronounce it "wabbit") is a suite of tools for WebAssembly, including: - - **wast2wasm**: translate from [WebAssembly text format](http://webassembly.github.io/spec/text/index.html) to the [WebAssembly binary format](http://webassembly.github.io/spec/binary/index.html) - - **wasm2wat**: the inverse of wast2wasm, translate from the binary format back to the text format (also known as a .wat) + - **wat2wasm**: translate from [WebAssembly text format](http://webassembly.github.io/spec/text/index.html) to the [WebAssembly binary format](http://webassembly.github.io/spec/binary/index.html) + - **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 - **wast-desugar**: parse .wast text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format @@ -25,7 +25,7 @@ target; instead they aim for full fidelity and compliance with the spec (e.g. Wabt has been compiled to JavaScript via emscripten. Some of the functionality is available in the following demos: - [index](https://cdn.rawgit.com/WebAssembly/wabt/7e56ca56/demo/index.html) -- [wast2wasm](https://cdn.rawgit.com/WebAssembly/wabt/7e56ca56/demo/wast2wasm/) +- [wat2wasm](https://cdn.rawgit.com/WebAssembly/wabt/7e56ca56/demo/wast2wasm/) - [wasm2wat](https://cdn.rawgit.com/WebAssembly/wabt/7e56ca56/demo/wasm2wast/) ## Cloning @@ -129,30 +129,30 @@ update-re2c` to update the prebuilt C sources in `src/prebuilt/`. CMake will detect if you don't have re2c installed and use the prebuilt source files instead. -## Running wast2wasm +## Running wat2wasm and wast2json Some examples: ```sh -# parse and typecheck test.wast -$ out/wast2wasm test.wast +# parse and typecheck test.wat +$ out/wat2wasm test.wat -# parse test.wast and write to binary file test.wasm -$ out/wast2wasm test.wast -o test.wasm +# parse test.wat and write to binary file test.wasm +$ out/wat2wasm test.wat -o test.wasm # parse spec-test.wast, and write verbose output to stdout (including the # meaning of every byte) -$ out/wast2wasm spec-test.wast -v +$ out/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. -$ out/wast2wasm spec-test.wast --spec -o spec-test.json +$ out/wast2json spec-test.wast -o spec-test.json ``` You can use `-h` to get additional help: ```console -$ out/wast2wasm -h +$ out/wat2wasm -h ``` Or try the [online demo](https://cdn.rawgit.com/WebAssembly/wabt/013802ca01035365e2459c70f0508481393ac075/demo/wast2wasm/). @@ -199,11 +199,11 @@ $ out/wasm-interp test.json --spec $ out/wasm-interp test.wasm -V 100 --run-all-exports ``` -As a convenience, you can use `test/run-interp.py` to convert a .wast file to +As a convenience, you can use `test/run-interp.py` to convert a .wat file to binary first, then run it in the interpreter: ```console -$ test/run-interp.py --spec spec-test.wast +$ test/run-interp.py --spec spec-test.wat 20/20 tests.passed. ``` diff --git a/demo/index.html b/demo/index.html index d395d1b7..912c1c9e 100644 --- a/demo/index.html +++ b/demo/index.html @@ -28,7 +28,7 @@ <hr> <ul> <li> - <a href="wast2wasm/">wast2wasm demo</a> + <a href="wat2wasm/">wat2wasm demo</a> <p> Example showing converting text to binary. </p> diff --git a/demo/wast2wasm/demo.js b/demo/wat2wasm/demo.js index 1f297583..1f297583 100644 --- a/demo/wast2wasm/demo.js +++ b/demo/wat2wasm/demo.js diff --git a/demo/wast2wasm/examples.js b/demo/wat2wasm/examples.js index 05f07571..05f07571 100644 --- a/demo/wast2wasm/examples.js +++ b/demo/wat2wasm/examples.js diff --git a/demo/wast2wasm/index.html b/demo/wat2wasm/index.html index 2b5d21d9..aca2405c 100644 --- a/demo/wast2wasm/index.html +++ b/demo/wat2wasm/index.html @@ -18,14 +18,14 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> - <title>wast2wasm demo</title> + <title>wat2wasm demo</title> <link href="../third_party/codemirror/codemirror.css" rel="stylesheet"> <link href="../primer.css" rel="stylesheet"> <link href="../custom.css" rel="stylesheet"> </head> <body> <div class="container"> - <h1>wast2wasm demo</h1> + <h1>wat2wasm demo</h1> <hr> <p>WebAssembly has a <a href="http://webassembly.github.io/spec/text/index.html">text format</a> diff --git a/scripts/fuzz-wast2wasm.sh b/scripts/fuzz-wat2wasm.sh index d77321f8..9f08fe51 100755 --- a/scripts/fuzz-wast2wasm.sh +++ b/scripts/fuzz-wat2wasm.sh @@ -21,4 +21,4 @@ set -o errexit SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" ROOT_DIR="$(dirname "${SCRIPT_DIR}")" -${FUZZ_BIN_DIR}/afl-fuzz -x fuzz-in/wast.dict -i fuzz-in/wast/ -o fuzz-out -- out/gcc-fuzz/Debug/wast2wasm @@ +${FUZZ_BIN_DIR}/afl-fuzz -x fuzz-in/wast.dict -i fuzz-in/wast/ -o fuzz-out -- out/gcc-fuzz/Debug/wat2wasm @@ diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index aba0e9f3..5c108405 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -476,7 +476,7 @@ struct Action { }; // An extremely simple JSON parser that only knows how to parse the expected -// format from wast2wasm. +// format from wat2wasm. class SpecJSONParser { public: SpecJSONParser() : thread_(&env_, s_thread_options) {} diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc new file mode 100644 index 00000000..7fb75c72 --- /dev/null +++ b/src/tools/wast2json.cc @@ -0,0 +1,130 @@ +/* + * Copyright 2016 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <cassert> +#include <cstdarg> +#include <cstdint> +#include <cstdlib> +#include <cstdio> +#include <string> + +#include "config.h" + +#include "src/binary-writer.h" +#include "src/binary-writer-spec.h" +#include "src/common.h" +#include "src/error-handler.h" +#include "src/feature.h" +#include "src/ir.h" +#include "src/option-parser.h" +#include "src/resolve-names.h" +#include "src/stream.h" +#include "src/validator.h" +#include "src/wast-parser.h" + +using namespace wabt; + +static const char* s_infile; +static const char* s_outfile; +static int s_verbose; +static WriteBinaryOptions s_write_binary_options; +static bool s_validate = true; +static bool s_debug_parsing; +static Features s_features; + +static std::unique_ptr<FileStream> s_log_stream; + +static const char s_description[] = +R"( read a file in the wasm spec test format, check it for errors, and + convert it to a JSON file and associated wasm binary files. + +examples: + # parse spec-test.wast, and write files to spec-test.json. Modules are + # written to spec-test.0.wasm, spec-test.1.wasm, etc. + $ wast2json spec-test.wast -o spec-test.json +)"; + +static void ParseOptions(int argc, char* argv[]) { + OptionParser parser("wast2json", s_description); + + parser.AddOption('v', "verbose", "Use multiple times for more info", []() { + s_verbose++; + s_log_stream = FileStream::CreateStdout(); + }); + parser.AddHelpOption(); + parser.AddOption("debug-parser", "Turn on debugging the parser of wast files", + []() { s_debug_parsing = true; }); + s_features.AddOptions(&parser); + parser.AddOption('o', "output", "FILE", "output wasm binary file", + [](const char* argument) { s_outfile = argument; }); + parser.AddOption( + 'r', "relocatable", + "Create a relocatable wasm binary (suitable for linking with wasm-link)", + []() { s_write_binary_options.relocatable = true; }); + parser.AddOption( + "no-canonicalize-leb128s", + "Write all LEB128 sizes as 5-bytes instead of their minimal size", + []() { s_write_binary_options.canonicalize_lebs = false; }); + parser.AddOption("debug-names", + "Write debug names to the generated binary file", + []() { s_write_binary_options.write_debug_names = true; }); + parser.AddOption("no-check", "Don't check for invalid modules", + []() { s_validate = false; }); + parser.AddArgument("filename", OptionParser::ArgumentCount::One, + [](const char* argument) { s_infile = argument; }); + + parser.Parse(argc, argv); +} + +int ProgramMain(int argc, char** argv) { + InitStdio(); + + ParseOptions(argc, argv); + + std::unique_ptr<WastLexer> lexer = WastLexer::CreateFileLexer(s_infile); + if (!lexer) + WABT_FATAL("unable to read file: %s\n", s_infile); + + ErrorHandlerFile error_handler(Location::Type::Text); + std::unique_ptr<Script> script; + WastParseOptions parse_wast_options(s_features); + Result result = + ParseWast(lexer.get(), &script, &error_handler, &parse_wast_options); + + if (Succeeded(result)) { + result = ResolveNamesScript(lexer.get(), script.get(), &error_handler); + + if (Succeeded(result) && s_validate) + result = ValidateScript(lexer.get(), script.get(), &error_handler); + + if (Succeeded(result)) { + WriteBinarySpecOptions write_binary_spec_options; + write_binary_spec_options.log_stream = s_log_stream.get(); + write_binary_spec_options.json_filename = s_outfile; + write_binary_spec_options.write_binary_options = s_write_binary_options; + result = WriteBinarySpecScript(script.get(), s_infile, + &write_binary_spec_options); + } + } + + return result != Result::Ok; +} + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wast2wasm.cc b/src/tools/wat2wasm.cc index bed3437f..20e27908 100644 --- a/src/tools/wast2wasm.cc +++ b/src/tools/wat2wasm.cc @@ -24,7 +24,6 @@ #include "config.h" #include "src/binary-writer.h" -#include "src/binary-writer-spec.h" #include "src/common.h" #include "src/error-handler.h" #include "src/feature.h" @@ -42,7 +41,6 @@ static const char* s_outfile; static bool s_dump_module; static int s_verbose; static WriteBinaryOptions s_write_binary_options; -static bool s_spec; static bool s_validate = true; static bool s_debug_parsing; static Features s_features; @@ -50,34 +48,30 @@ static Features s_features; static std::unique_ptr<FileStream> s_log_stream; static const char s_description[] = -R"( read a file in the wasm s-expression format, check it for errors, and +R"( read a file in the wasm text format, check it for errors, and convert it to the wasm binary format. examples: - # parse and typecheck test.wast - $ wast2wasm test.wast + # parse and typecheck test.wat + $ wat2wasm test.wat - # parse test.wast and write to binary file test.wasm - $ wast2wasm test.wast -o test.wasm + # parse test.wat and write to binary file test.wasm + $ wat2wasm test.wat -o test.wasm # parse spec-test.wast, and write verbose output to stdout (including # the meaning of every byte) - $ wast2wasm 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. - $ wast2wasm spec-test.wast --spec -o spec-test.json + $ wat2wasm spec-test.wast -v )"; static void ParseOptions(int argc, char* argv[]) { - OptionParser parser("wast2wasm", s_description); + OptionParser parser("wat2wasm", s_description); parser.AddOption('v', "verbose", "Use multiple times for more info", []() { s_verbose++; s_log_stream = FileStream::CreateStdout(); }); parser.AddHelpOption(); - parser.AddOption("debug-parser", "Turn on debugging the parser of wast files", + parser.AddOption("debug-parser", "Turn on debugging the parser of wat files", []() { s_debug_parsing = true; }); parser.AddOption('d', "dump-module", "Print a hexdump of the module to stdout", @@ -90,10 +84,6 @@ static void ParseOptions(int argc, char* argv[]) { "Create a relocatable wasm binary (suitable for linking with wasm-link)", []() { s_write_binary_options.relocatable = true; }); parser.AddOption( - "spec", - "Parse a file with multiple modules and assertions, like the spec tests", - []() { s_spec = true; }); - parser.AddOption( "no-canonicalize-leb128s", "Write all LEB128 sizes as 5-bytes instead of their minimal size", []() { s_write_binary_options.canonicalize_lebs = false; }); @@ -133,6 +123,7 @@ int ProgramMain(int argc, char** argv) { WABT_FATAL("unable to read file: %s\n", s_infile); ErrorHandlerFile error_handler(Location::Type::Text); + // TODO(binji): Parse Module instead of Script. std::unique_ptr<Script> script; WastParseOptions parse_wast_options(s_features); Result result = @@ -145,25 +136,16 @@ int ProgramMain(int argc, char** argv) { result = ValidateScript(lexer.get(), script.get(), &error_handler); if (Succeeded(result)) { - if (s_spec) { - WriteBinarySpecOptions write_binary_spec_options; - write_binary_spec_options.log_stream = s_log_stream.get(); - write_binary_spec_options.json_filename = s_outfile; - write_binary_spec_options.write_binary_options = s_write_binary_options; - result = WriteBinarySpecScript(script.get(), s_infile, - &write_binary_spec_options); + MemoryStream stream(s_log_stream.get()); + const Module* module = script->GetFirstModule(); + if (module) { + result = WriteBinaryModule(&stream, module, &s_write_binary_options); } else { - MemoryStream stream(s_log_stream.get()); - const Module* module = script->GetFirstModule(); - if (module) { - result = WriteBinaryModule(&stream, module, &s_write_binary_options); - } else { - WABT_FATAL("no module found\n"); - } - - if (Succeeded(result)) - WriteBufferToFile(s_outfile, stream.output_buffer()); + WABT_FATAL("no module found\n"); } + + if (Succeeded(result)) + WriteBufferToFile(s_outfile, stream.output_buffer()); } } diff --git a/test/README.md b/test/README.md index 207ab633..297c356d 100644 --- a/test/README.md +++ b/test/README.md @@ -95,12 +95,12 @@ expected stderr ``` The test runner will copy the input to a temporary file and pass it as an -argument to the executable (which by default is `out/wast2wasm`). +argument to the executable (which by default is `out/wat2wasm`). The currently supported list of keys: - `TOOL`: a set of preconfigured keys, see below. -- `EXE`: the executable to run, defaults to out/wast2wasm +- `EXE`: the executable to run, defaults to out/wat2wasm - `STDIN_FILE`: the file to use for STDIN instead of the contents of this file. - `FLAGS`: additional flags to pass to the executable - `ENV`: environment variables to set, separated by spaces @@ -112,7 +112,7 @@ The currently supported list of keys: The currently supported list of tools (see [run-tests.py](https://github.com/WebAssembly/wabt/blob/master/test/run-tests.py#L44)): -- `wast2wasm`: parse a wasm text file and validate it. +- `wat2wasm`: parse a wasm text file and validate it. - `wast-desugar`: parse the wasm text file and rewrite it in the canonical text format. - `run-objdump`: parse a wasm text file, convert it to binary, then run @@ -150,11 +150,11 @@ There's otherwise no logic attached to a test being in a given directory. Here is a brief description of the tests are contained in each top-level subdirectory: -- `binary`: Tests binary files that are impossible to generate via wast2wasm. +- `binary`: Tests binary files that are impossible to generate via wat2wasm. Typically these are illegal binary files, to ensure binary file reading is robust. - `desugar`: Tests the `wast-desugar` tool. -- `dump`: Tests the verbose output of `wast2wasm` and the output of +- `dump`: Tests the verbose output of `wat2wasm` and the output of `wasm-objdump`. - `exceptions`: Tests the new experimental exceptions feature. - `gen-spec-js`: Tests the gen-spec-js tool, which converts a spec test into a @@ -163,7 +163,7 @@ subdirectory: - `interp`: Tests the `wasm-interp` tool. - `link`: Tests the `wasm-link` tool. - `opcodecnt`: Tests the `wasm-opcodecnt` tool. -- `parse`: Tests parsing via the `wast2wasm` tool. +- `parse`: Tests parsing via the `wat2wasm` tool. - `regress`: Various regression tests that are irregular and don't fit naturally in the other directories. - `roundtrip`: Tests that roundtripping the text to binary and back to text @@ -172,7 +172,7 @@ subdirectory: `gen-wasm.py` and should be placed in the `binary` directory instead). - `spec`: All of the spec core tests. These tests are auto-generated by the `update-spec-tests.py` script. -- `typecheck`: Tests the wast validation in the `wast2wasm` tool. +- `typecheck`: Tests the wast validation in the `wat2wasm` tool. ## Writing New Tests diff --git a/test/exceptions/bad-throw.txt b/test/exceptions/bad-throw.txt index 5558c8a7..b02b3e6e 100644 --- a/test/exceptions/bad-throw.txt +++ b/test/exceptions/bad-throw.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v ;;; ERROR: 1 (module diff --git a/test/exceptions/bad-try.txt b/test/exceptions/bad-try.txt index 2321da47..808235fd 100644 --- a/test/exceptions/bad-try.txt +++ b/test/exceptions/bad-try.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; ERROR: 1 (module (func (result i32) diff --git a/test/exceptions/catch-all-not-last.txt b/test/exceptions/catch-all-not-last.txt index 67cbcdc6..6833c807 100644 --- a/test/exceptions/catch-all-not-last.txt +++ b/test/exceptions/catch-all-not-last.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v ;;; ERROR: 1 (module diff --git a/test/exceptions/rethrow-not-in-catch.txt b/test/exceptions/rethrow-not-in-catch.txt index cfa9a3a2..2f9c4cb3 100644 --- a/test/exceptions/rethrow-not-in-catch.txt +++ b/test/exceptions/rethrow-not-in-catch.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v ;;; ERROR: 1 (module diff --git a/test/exceptions/rethrow-to-wrong-block.txt b/test/exceptions/rethrow-to-wrong-block.txt index 8bd08e60..9a932706 100644 --- a/test/exceptions/rethrow-to-wrong-block.txt +++ b/test/exceptions/rethrow-to-wrong-block.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v ;;; ERROR: 1 (module diff --git a/test/exceptions/try-exports.txt b/test/exceptions/try-exports.txt index b1310ba2..500c87c8 100644 --- a/test/exceptions/try-exports.txt +++ b/test/exceptions/try-exports.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v (module (except $ex i32) diff --git a/test/exceptions/try-imports.txt b/test/exceptions/try-imports.txt index 85f854e8..51b09947 100644 --- a/test/exceptions/try-imports.txt +++ b/test/exceptions/try-imports.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v (module (import "c++" "except" (except $ex i32)) diff --git a/test/exceptions/try-text.txt b/test/exceptions/try-text.txt index 3f2d5adb..4247b744 100644 --- a/test/exceptions/try-text.txt +++ b/test/exceptions/try-text.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v (module (except $ex i32) diff --git a/test/exceptions/try.txt b/test/exceptions/try.txt index a18a977b..879aff7c 100644 --- a/test/exceptions/try.txt +++ b/test/exceptions/try.txt @@ -1,4 +1,4 @@ -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; FLAGS: --enable-exceptions -v (module (except $ex i32) diff --git a/test/find_exe.py b/test/find_exe.py index d05fac18..a7046605 100644 --- a/test/find_exe.py +++ b/test/find_exe.py @@ -24,8 +24,8 @@ IS_WINDOWS = sys.platform == 'win32' SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) REPO_ROOT_DIR = os.path.dirname(SCRIPT_DIR) EXECUTABLES = [ - 'wast2wasm', 'wasm2wat', 'wasm-objdump', 'wasm-interp', 'wasm-opcodecnt', - 'wast-desugar', 'wasm-link' + 'wat2wasm', 'wast2json', 'wasm2wat', 'wasm-objdump', 'wasm-interp', + 'wasm-opcodecnt', 'wast-desugar', 'wasm-link' ] @@ -64,8 +64,12 @@ def FindExecutable(basename, override=None): return FindExeWithFallback(basename, [GetDefaultExe(basename)], override) -def GetWast2WasmExecutable(override=None): - return FindExecutable('wast2wasm', override) +def GetWat2WasmExecutable(override=None): + return FindExecutable('wat2wasm', override) + + +def GetWast2JsonExecutable(override=None): + return FindExecutable('wast2json', override) def GetWasm2WatExecutable(override=None): diff --git a/test/gen-spec-js.py b/test/gen-spec-js.py index 40d22020..5e8d65ca 100755 --- a/test/gen-spec-js.py +++ b/test/gen-spec-js.py @@ -134,7 +134,7 @@ def F64ToJS(f64_bits): def UnescapeWasmString(s): - # Wast allows for more escape characters than this, but we assume that + # Wat allows for more escape characters than this, but we assume that # wasm2wat will only use the \xx escapes. result = '' i = 0 @@ -218,29 +218,29 @@ def CollectInvalidModuleCommands(commands): class ModuleExtender(object): - def __init__(self, wast2wasm, wasm2wat, temp_dir): - self.wast2wasm = wast2wasm + def __init__(self, wat2wasm, wasm2wat, temp_dir): + self.wat2wasm = wat2wasm self.wasm2wat = wasm2wat self.temp_dir = temp_dir self.lines = [] self.exports = {} def Extend(self, wasm_path, commands): - wast_path = self._RunWasm2Wat(wasm_path) - with open(wast_path) as wast_file: - wast = wast_file.read() + wat_path = self._RunWasm2Wat(wasm_path) + with open(wat_path) as wat_file: + wat = wat_file.read() self.lines = [] - self.exports = self._GetExports(wast) + self.exports = self._GetExports(wat) for i, command in enumerate(commands): self._Command(i, command) - wast = wast[:wast.rindex(')')] + '\n\n' - wast += '\n'.join(self.lines) + ')' - # print wast - with open(wast_path, 'w') as wast_file: - wast_file.write(wast) - return self._RunWast2Wasm(wast_path) + wat = wat[:wat.rindex(')')] + '\n\n' + wat += '\n'.join(self.lines) + ')' + # print wat + with open(wat_path, 'w') as wat_file: + wat_file.write(wat) + return self._RunWat2Wasm(wat_path) def _Command(self, index, command): command_type = command['type'] @@ -288,10 +288,10 @@ class ModuleExtender(object): # Change the command to assert_return, it won't return NaN anymore. command['type'] = 'assert_return' - def _GetExports(self, wast): + def _GetExports(self, wat): result = {} pattern = r'^\s*\(export \"(.*?)\"\s*\((\w+) (\d+)' - for name, type_, index in re.findall(pattern, wast, re.MULTILINE): + for name, type_, index in re.findall(pattern, wat, re.MULTILINE): result[UnescapeWasmString(name)] = (type_, index) return result @@ -366,13 +366,13 @@ class ModuleExtender(object): self.lines.append(inst) def _RunWasm2Wat(self, wasm_path): - wast_path = ChangeDir(ChangeExt(wasm_path, '.wast'), self.temp_dir) - self.wasm2wat.RunWithArgs(wasm_path, '-o', wast_path) - return wast_path + wat_path = ChangeDir(ChangeExt(wasm_path, '.wat'), self.temp_dir) + self.wasm2wat.RunWithArgs(wasm_path, '-o', wat_path) + return wat_path - def _RunWast2Wasm(self, wast_path): - wasm_path = ChangeDir(ChangeExt(wast_path, '.wasm'), self.temp_dir) - self.wast2wasm.RunWithArgs(wast_path, '-o', wasm_path) + def _RunWat2Wasm(self, wat_path): + wasm_path = ChangeDir(ChangeExt(wat_path, '.wasm'), self.temp_dir) + self.wat2wasm.RunWithArgs(wat_path, '-o', wasm_path) return wasm_path @@ -484,7 +484,7 @@ def main(args): default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument('--temp-dir', metavar='PATH', - help='set the directory that temporary wasm/wast' + help='set the directory that temporary wasm/wat' ' files are written.') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' @@ -496,14 +496,14 @@ def main(args): parser.add_argument('file', help='spec json file.') options = parser.parse_args(args) - wast2wasm = Executable( - find_exe.GetWast2WasmExecutable(options.bindir), + wat2wasm = Executable( + find_exe.GetWat2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat = Executable( find_exe.GetWasm2WatExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.verbose = options.print_cmd + wat2wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd with open(options.file) as json_file: @@ -515,7 +515,7 @@ def main(args): modules = CollectInvalidModuleCommands(all_commands) with utils.TempDirectory(options.temp_dir, 'gen-spec-js-') as temp_dir: - extender = ModuleExtender(wast2wasm, wasm2wat, temp_dir) + extender = ModuleExtender(wat2wasm, wasm2wat, temp_dir) for module_command, assert_commands in modules: if assert_commands: wasm_path = os.path.join(json_dir, module_command['filename']) diff --git a/test/help/wast2json.txt b/test/help/wast2json.txt new file mode 100644 index 00000000..ebf9564b --- /dev/null +++ b/test/help/wast2json.txt @@ -0,0 +1,26 @@ +;;; EXE: %(wast2json)s +;;; FLAGS: --help +(;; STDOUT ;;; +usage: wast2json [options] filename + + read a file in the wasm spec test format, check it for errors, and + convert it to a JSON file and associated wasm binary files. + +examples: + # parse spec-test.wast, and write files to spec-test.json. Modules are + # written to spec-test.0.wasm, spec-test.1.wasm, etc. + $ wast2json spec-test.wast -o spec-test.json + +options: + -v, --verbose Use multiple times for more info + -h, --help Print this help message + --debug-parser Turn on debugging the parser of wast files + --enable-exceptions Experimental exception handling + --enable-saturating-float-to-int Saturating float-to-int operators + --enable-threads Threading support + -o, --output=FILE output wasm binary file + -r, --relocatable Create a relocatable wasm binary (suitable for linking with wasm-link) + --no-canonicalize-leb128s Write all LEB128 sizes as 5-bytes instead of their minimal size + --debug-names Write debug names to the generated binary file + --no-check Don't check for invalid modules +;;; STDOUT ;;) diff --git a/test/help/wast2wasm.txt b/test/help/wat2wasm.txt index 0e4cdfa0..16ed27ea 100644 --- a/test/help/wast2wasm.txt +++ b/test/help/wat2wasm.txt @@ -1,37 +1,32 @@ -;;; EXE: %(wast2wasm)s +;;; EXE: %(wat2wasm)s ;;; FLAGS: --help (;; STDOUT ;;; -usage: wast2wasm [options] filename +usage: wat2wasm [options] filename - read a file in the wasm s-expression format, check it for errors, and + read a file in the wasm text format, check it for errors, and convert it to the wasm binary format. examples: - # parse and typecheck test.wast - $ wast2wasm test.wast + # parse and typecheck test.wat + $ wat2wasm test.wat - # parse test.wast and write to binary file test.wasm - $ wast2wasm test.wast -o test.wasm + # parse test.wat and write to binary file test.wasm + $ wat2wasm test.wat -o test.wasm # parse spec-test.wast, and write verbose output to stdout (including # the meaning of every byte) - $ wast2wasm 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. - $ wast2wasm spec-test.wast --spec -o spec-test.json + $ wat2wasm spec-test.wast -v options: -v, --verbose Use multiple times for more info -h, --help Print this help message - --debug-parser Turn on debugging the parser of wast files + --debug-parser Turn on debugging the parser of wat files -d, --dump-module Print a hexdump of the module to stdout --enable-exceptions Experimental exception handling --enable-saturating-float-to-int Saturating float-to-int operators --enable-threads Threading support -o, --output=FILE output wasm binary file -r, --relocatable Create a relocatable wasm binary (suitable for linking with wasm-link) - --spec Parse a file with multiple modules and assertions, like the spec tests --no-canonicalize-leb128s Write all LEB128 sizes as 5-bytes instead of their minimal size --debug-names Write debug names to the generated binary file --no-check Don't check for invalid modules diff --git a/test/parse/assert/assert-after-module.txt b/test/parse/assert/assert-after-module.txt index caa09bc3..6887e79e 100644 --- a/test/parse/assert/assert-after-module.txt +++ b/test/parse/assert/assert-after-module.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (module (export "f" (func 0)) (func (result i32) diff --git a/test/parse/assert/assert-return-arithmetic-nan.txt b/test/parse/assert/assert-return-arithmetic-nan.txt index 0d135b1c..ac185883 100644 --- a/test/parse/assert/assert-return-arithmetic-nan.txt +++ b/test/parse/assert/assert-return-arithmetic-nan.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (module (func $foo (param f32) (result f32) get_local 0 diff --git a/test/parse/assert/assert-return-canonical-nan.txt b/test/parse/assert/assert-return-canonical-nan.txt index d586833e..fc973f9c 100644 --- a/test/parse/assert/assert-return-canonical-nan.txt +++ b/test/parse/assert/assert-return-canonical-nan.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (module (func $foo (param f32) (result f32) get_local 0 diff --git a/test/parse/assert/assertinvalid-binary-module.txt b/test/parse/assert/assertinvalid-binary-module.txt index 47338550..58ce33ab 100644 --- a/test/parse/assert/assertinvalid-binary-module.txt +++ b/test/parse/assert/assertinvalid-binary-module.txt @@ -1,3 +1,3 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (assert_invalid (module binary "\00ASM") "bad magic") (module) diff --git a/test/parse/assert/assertinvalid.txt b/test/parse/assert/assertinvalid.txt index 511a7f7f..85090839 100644 --- a/test/parse/assert/assertinvalid.txt +++ b/test/parse/assert/assertinvalid.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (assert_invalid (module (func diff --git a/test/parse/assert/assertmalformed.txt b/test/parse/assert/assertmalformed.txt index 30559e01..34827fa9 100644 --- a/test/parse/assert/assertmalformed.txt +++ b/test/parse/assert/assertmalformed.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (assert_malformed (module binary "\00asm\bc\0a\00\00") diff --git a/test/parse/assert/assertreturn.txt b/test/parse/assert/assertreturn.txt index 301dcf78..8339d773 100644 --- a/test/parse/assert/assertreturn.txt +++ b/test/parse/assert/assertreturn.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (module (func $foo (result i32) i32.const 0) (export "foo" (func $foo)) diff --git a/test/parse/assert/bad-assert-before-module.txt b/test/parse/assert/bad-assert-before-module.txt index 031b6203..6bade1bd 100644 --- a/test/parse/assert/bad-assert-before-module.txt +++ b/test/parse/assert/bad-assert-before-module.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json ;;; ERROR: 1 (assert_return (invoke "f") (i32.const 0)) (;; STDERR ;;; diff --git a/test/parse/assert/bad-assert-return-arithmetic-nan-invalid-return-type.txt b/test/parse/assert/bad-assert-return-arithmetic-nan-invalid-return-type.txt index 08bf4bc8..97b8ffae 100644 --- a/test/parse/assert/bad-assert-return-arithmetic-nan-invalid-return-type.txt +++ b/test/parse/assert/bad-assert-return-arithmetic-nan-invalid-return-type.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (result i32) i32.const 0) diff --git a/test/parse/assert/bad-assert-return-arithmetic-nan-too-few.txt b/test/parse/assert/bad-assert-return-arithmetic-nan-too-few.txt index fe1a5ca6..498fe9e0 100644 --- a/test/parse/assert/bad-assert-return-arithmetic-nan-too-few.txt +++ b/test/parse/assert/bad-assert-return-arithmetic-nan-too-few.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (param i32) (result f32) f32.const 0) diff --git a/test/parse/assert/bad-assert-return-arithmetic-nan-too-many.txt b/test/parse/assert/bad-assert-return-arithmetic-nan-too-many.txt index 0a73e02a..c2e258f4 100644 --- a/test/parse/assert/bad-assert-return-arithmetic-nan-too-many.txt +++ b/test/parse/assert/bad-assert-return-arithmetic-nan-too-many.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (result f32) f32.const 0) diff --git a/test/parse/assert/bad-assert-return-arithmetic-nan-unknown-function.txt b/test/parse/assert/bad-assert-return-arithmetic-nan-unknown-function.txt index aba879ca..24e371f3 100644 --- a/test/parse/assert/bad-assert-return-arithmetic-nan-unknown-function.txt +++ b/test/parse/assert/bad-assert-return-arithmetic-nan-unknown-function.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module) (assert_return_arithmetic_nan (invoke "foo")) (;; STDERR ;;; diff --git a/test/parse/assert/bad-assert-return-canonical-nan-invalid-return-type.txt b/test/parse/assert/bad-assert-return-canonical-nan-invalid-return-type.txt index ae57b5b1..005c4ff6 100644 --- a/test/parse/assert/bad-assert-return-canonical-nan-invalid-return-type.txt +++ b/test/parse/assert/bad-assert-return-canonical-nan-invalid-return-type.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (result i32) i32.const 0) diff --git a/test/parse/assert/bad-assert-return-canonical-nan-too-few.txt b/test/parse/assert/bad-assert-return-canonical-nan-too-few.txt index 8520a26a..73c40241 100644 --- a/test/parse/assert/bad-assert-return-canonical-nan-too-few.txt +++ b/test/parse/assert/bad-assert-return-canonical-nan-too-few.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (param i32) (result f32) f32.const 0) diff --git a/test/parse/assert/bad-assert-return-canonical-nan-too-many.txt b/test/parse/assert/bad-assert-return-canonical-nan-too-many.txt index 8fef859b..acae9b3f 100644 --- a/test/parse/assert/bad-assert-return-canonical-nan-too-many.txt +++ b/test/parse/assert/bad-assert-return-canonical-nan-too-many.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (result f32) f32.const 0) diff --git a/test/parse/assert/bad-assert-return-canonical-nan-unknown-function.txt b/test/parse/assert/bad-assert-return-canonical-nan-unknown-function.txt index 7f69f31e..0d614bc1 100644 --- a/test/parse/assert/bad-assert-return-canonical-nan-unknown-function.txt +++ b/test/parse/assert/bad-assert-return-canonical-nan-unknown-function.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module) (assert_return_canonical_nan (invoke "foo")) (;; STDERR ;;; diff --git a/test/parse/assert/bad-assertreturn-non-const.txt b/test/parse/assert/bad-assertreturn-non-const.txt index a05ef85a..ee805c75 100644 --- a/test/parse/assert/bad-assertreturn-non-const.txt +++ b/test/parse/assert/bad-assertreturn-non-const.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $bar (param f32) (result f32) get_local 0) diff --git a/test/parse/assert/bad-assertreturn-too-few.txt b/test/parse/assert/bad-assertreturn-too-few.txt index 5c73c2ee..e969883c 100644 --- a/test/parse/assert/bad-assertreturn-too-few.txt +++ b/test/parse/assert/bad-assertreturn-too-few.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (param i32) (result i32) get_local 0) diff --git a/test/parse/assert/bad-assertreturn-too-many.txt b/test/parse/assert/bad-assertreturn-too-many.txt index 3ea0637e..ed72a44e 100644 --- a/test/parse/assert/bad-assertreturn-too-many.txt +++ b/test/parse/assert/bad-assertreturn-too-many.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func $foo (result i32) i32.const 0) diff --git a/test/parse/assert/bad-assertreturn-unknown-function.txt b/test/parse/assert/bad-assertreturn-unknown-function.txt index c4f981f7..929e5b75 100644 --- a/test/parse/assert/bad-assertreturn-unknown-function.txt +++ b/test/parse/assert/bad-assertreturn-unknown-function.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module) (assert_return (invoke "foo") (i32.const 0)) (;; STDERR ;;; diff --git a/test/parse/assert/bad-invoke-no-module.txt b/test/parse/assert/bad-invoke-no-module.txt index a761c5a2..801a2a98 100644 --- a/test/parse/assert/bad-invoke-no-module.txt +++ b/test/parse/assert/bad-invoke-no-module.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (invoke "foo") (;; STDERR ;;; out/test/parse/assert/bad-invoke-no-module.txt:3:2: error: unknown module diff --git a/test/parse/assert/bad-invoke-too-few.txt b/test/parse/assert/bad-invoke-too-few.txt index 4554cb8f..c1e34e11 100644 --- a/test/parse/assert/bad-invoke-too-few.txt +++ b/test/parse/assert/bad-invoke-too-few.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func (param i32)) (export "foo" (func 0))) diff --git a/test/parse/assert/bad-invoke-too-many.txt b/test/parse/assert/bad-invoke-too-many.txt index cd2df9bd..e55eb4f0 100644 --- a/test/parse/assert/bad-invoke-too-many.txt +++ b/test/parse/assert/bad-invoke-too-many.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func (param i32)) (export "foo" (func 0))) diff --git a/test/parse/assert/bad-invoke-unknown-function.txt b/test/parse/assert/bad-invoke-unknown-function.txt index 26f0c0ff..f5db4509 100644 --- a/test/parse/assert/bad-invoke-unknown-function.txt +++ b/test/parse/assert/bad-invoke-unknown-function.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (export "foo" (func $foo)) (func $foo)) diff --git a/test/parse/assert/invoke.txt b/test/parse/assert/invoke.txt index 393c000e..fba32549 100644 --- a/test/parse/assert/invoke.txt +++ b/test/parse/assert/invoke.txt @@ -1,4 +1,4 @@ -;;; FLAGS: --spec +;;; TOOL: wast2json (module (export "test" (func $test)) (func $test (param i32) (result i32) diff --git a/test/parse/force-color.txt b/test/parse/force-color.txt index a898631d..304b8b8d 100644 --- a/test/parse/force-color.txt +++ b/test/parse/force-color.txt @@ -1,5 +1,5 @@ ;;; ERROR: 1 -;;; TOOL: wast2wasm +;;; TOOL: wat2wasm ;;; ENV: FORCE_COLOR=1 (module (func badname (param i32) (result badtype) diff --git a/test/run-gen-spec-js.py b/test/run-gen-spec-js.py index 5afc5f9e..a80a2464 100755 --- a/test/run-gen-spec-js.py +++ b/test/run-gen-spec-js.py @@ -54,14 +54,14 @@ def main(args): parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') - parser.add_argument('file', help='wast file.') + parser.add_argument('file', help='wat file.') options = parser.parse_args(args) with utils.TempDirectory(options.out_dir, 'run-gen-spec-js-') as out_dir: - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), '--spec', + wast2json = utils.Executable( + find_exe.GetWast2JsonExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({'-v': options.verbose}) + wast2json.AppendOptionalArgs({'-v': options.verbose}) gen_spec_js = utils.Executable(sys.executable, GEN_SPEC_JS_PY, '--temp-dir', out_dir, @@ -75,7 +75,7 @@ def main(args): json_file = utils.ChangeDir( utils.ChangeExt(options.file, '.json'), out_dir) js_file = utils.ChangeExt(json_file, '.js') - wast2wasm.RunWithArgs(options.file, '-o', json_file) + wast2json.RunWithArgs(options.file, '-o', json_file) if options.js_engine: gen_spec_js.RunWithArgs(json_file, '-o', js_file) diff --git a/test/run-interp.py b/test/run-interp.py index 27aa081b..664a6d87 100755 --- a/test/run-interp.py +++ b/test/run-interp.py @@ -51,12 +51,18 @@ def main(args): parser.add_argument('--enable-threads', action='store_true') options = parser.parse_args(args) - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), - error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({ + wast_tool = None + if options.spec: + wast_tool = utils.Executable( + find_exe.GetWast2JsonExecutable(options.bindir), + error_cmdline=options.error_cmdline) + else: + wast_tool = utils.Executable( + find_exe.GetWat2WasmExecutable(options.bindir), + error_cmdline=options.error_cmdline) + + wast_tool.AppendOptionalArgs({ '-v': options.verbose, - '--spec': options.spec, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, @@ -75,13 +81,13 @@ def main(args): '--enable-threads': options.enable_threads, }) - wast2wasm.verbose = options.print_cmd + wast_tool.verbose = options.print_cmd wasm_interp.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir: new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) - wast2wasm.RunWithArgs(options.file, '-o', out_file) + wast_tool.RunWithArgs(options.file, '-o', out_file) wasm_interp.RunWithArgs(out_file) return 0 diff --git a/test/run-objdump.py b/test/run-objdump.py index 56411876..e86a1b22 100755 --- a/test/run-objdump.py +++ b/test/run-objdump.py @@ -44,7 +44,6 @@ def main(args): action='store_true') parser.add_argument('--headers', action='store_true') parser.add_argument('--no-check', action='store_true') - parser.add_argument('-c', '--compile-only', action='store_true') parser.add_argument('--dump-verbose', action='store_true') parser.add_argument('--dump-debug', action='store_true') parser.add_argument('--enable-exceptions', action='store_true') @@ -65,10 +64,17 @@ def main(args): gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline) - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), - error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({ + wat_tool = None + if options.spec: + wat_tool = utils.Executable( + find_exe.GetWast2JsonExecutable(options.bindir), + error_cmdline=options.error_cmdline) + else: + wat_tool = utils.Executable( + find_exe.GetWat2WasmExecutable(options.bindir), + error_cmdline=options.error_cmdline) + + wat_tool.AppendOptionalArgs({ '--debug-names': options.debug_names, '--enable-exceptions': options.enable_exceptions, '--enable-saturating-float-to-int': @@ -76,10 +82,8 @@ def main(args): '--enable-threads': options.enable_threads, '--no-check': options.no_check, '--no-canonicalize-leb128s': options.no_canonicalize_leb128s, - '--spec': options.spec, '-v': options.verbose, '-r': options.relocatable, - '-c': options.compile_only, }) wasm_objdump = utils.Executable( @@ -96,7 +100,7 @@ def main(args): }) gen_wasm.verbose = options.print_cmd - wast2wasm.verbose = options.print_cmd + wat_tool.verbose = options.print_cmd wasm_objdump.verbose = options.print_cmd filename = options.file @@ -112,7 +116,7 @@ def main(args): out_file = os.path.join(out_dir, basename_noext + '.json') else: out_file = os.path.join(out_dir, basename_noext + '.wasm') - wast2wasm.RunWithArgs('-o', out_file, filename) + wat_tool.RunWithArgs('-o', out_file, filename) if options.spec: wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file) diff --git a/test/run-opcodecnt.py b/test/run-opcodecnt.py index 741a0e6b..4b508bdd 100644 --- a/test/run-opcodecnt.py +++ b/test/run-opcodecnt.py @@ -46,10 +46,10 @@ def main(args): parser.add_argument('file', help='test file.') options = parser.parse_args(args) - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), + wat2wasm = utils.Executable( + find_exe.GetWat2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({ + wat2wasm.AppendOptionalArgs({ '-v': options.verbose, }) @@ -57,12 +57,12 @@ def main(args): find_exe.GetWasmOpcodeCntExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.verbose = options.print_cmd + wat2wasm.verbose = options.print_cmd wasm_opcodecnt.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-opcodecnt-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) - wast2wasm.RunWithArgs(options.file, '-o', out_file) + wat2wasm.RunWithArgs(options.file, '-o', out_file) wasm_opcodecnt.RunWithArgs(out_file, '-c', str(options.cutoff)) return 0 diff --git a/test/run-roundtrip.py b/test/run-roundtrip.py index 47245f57..bce745c5 100755 --- a/test/run-roundtrip.py +++ b/test/run-roundtrip.py @@ -57,32 +57,32 @@ def FilesAreEqual(filename1, filename2, verbose=False): return (OK, '') -def TwoRoundtrips(wast2wasm, wasm2wat, out_dir, filename, verbose): +def TwoRoundtrips(wat2wasm, wasm2wat, out_dir, filename, verbose): basename = os.path.basename(filename) basename_noext = os.path.splitext(basename)[0] wasm1_file = os.path.join(out_dir, basename_noext + '-1.wasm') wast2_file = os.path.join(out_dir, basename_noext + '-2.wast') wasm3_file = os.path.join(out_dir, basename_noext + '-3.wasm') try: - wast2wasm.RunWithArgs('-o', wasm1_file, filename) + wat2wasm.RunWithArgs('-o', wasm1_file, filename) except Error as e: # if the file doesn't parse properly, just skip it (it may be a "bad-*" # test) return (SKIPPED, None) try: wasm2wat.RunWithArgs('-o', wast2_file, wasm1_file) - wast2wasm.RunWithArgs('-o', wasm3_file, wast2_file) + wat2wasm.RunWithArgs('-o', wasm3_file, wast2_file) except Error as e: return (ERROR, str(e)) return FilesAreEqual(wasm1_file, wasm3_file, verbose) -def OneRoundtripToStdout(wast2wasm, wasm2wat, out_dir, filename, verbose): +def OneRoundtripToStdout(wat2wasm, wasm2wat, out_dir, filename, verbose): basename = os.path.basename(filename) basename_noext = os.path.splitext(basename)[0] wasm_file = os.path.join(out_dir, basename_noext + '.wasm') try: - wast2wasm.RunWithArgs('-o', wasm_file, filename) + wat2wasm.RunWithArgs('-o', wasm_file, filename) except Error as e: # if the file doesn't parse properly, just skip it (it may be a "bad-*" # test) @@ -121,10 +121,10 @@ def main(args): parser.add_argument('file', help='test file.') options = parser.parse_args(args) - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), + wat2wasm = utils.Executable( + find_exe.GetWat2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({ + wat2wasm.AppendOptionalArgs({ '--debug-names': options.debug_names, '--enable-exceptions': options.enable_exceptions, '--no-check': options.no_check, @@ -142,7 +142,7 @@ def main(args): '--no-check': options.no_check, }) - wast2wasm.verbose = options.print_cmd + wat2wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd filename = options.file @@ -152,10 +152,10 @@ def main(args): with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir: if options.stdout: - result, msg = OneRoundtripToStdout(wast2wasm, wasm2wat, out_dir, + result, msg = OneRoundtripToStdout(wat2wasm, wasm2wat, out_dir, filename, options.verbose) else: - result, msg = TwoRoundtrips(wast2wasm, wasm2wat, out_dir, filename, + result, msg = TwoRoundtrips(wat2wasm, wasm2wat, out_dir, filename, options.verbose) if result == ERROR: sys.stderr.write(msg) diff --git a/test/run-tests.py b/test/run-tests.py index 0d6b9405..07e3d22b 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -42,8 +42,12 @@ SLOW_TIMEOUT_MULTIPLIER = 2 # default configurations for tests TOOLS = { - 'wast2wasm': { - 'EXE': '%(wast2wasm)s', + 'wat2wasm': { + 'EXE': '%(wat2wasm)s', + 'VERBOSE-FLAGS': ['-v'] + }, + 'wast2json': { + 'EXE': '%(wast2json)s', 'VERBOSE-FLAGS': ['-v'] }, 'wast-desugar': { @@ -139,7 +143,7 @@ TOOLS = { }, } -ROUNDTRIP_TOOLS = ('wast2wasm',) +ROUNDTRIP_TOOLS = ('wat2wasm',) def Indent(s, spaces): @@ -228,8 +232,8 @@ class TestInfo(object): self.input_ = '' self.expected_stdout = '' self.expected_stderr = '' - self.tool = 'wast2wasm' - self.exe = '%(wast2wasm)s' + self.tool = 'wat2wasm' + self.exe = '%(wat2wasm)s' self.flags = [] self.env = {} self.last_cmd = '' diff --git a/test/run-wasm-link.py b/test/run-wasm-link.py index 0387fa50..6fb24b1b 100755 --- a/test/run-wasm-link.py +++ b/test/run-wasm-link.py @@ -53,10 +53,10 @@ def main(args): parser.add_argument('file', help='test file.') options = parser.parse_args(args) - wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.bindir), + wast2json = utils.Executable( + find_exe.GetWast2JsonExecutable(options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.AppendOptionalArgs({ + wast2json.AppendOptionalArgs({ '--debug-names': options.debug_names, '-v': options.dump_verbose, }) @@ -76,7 +76,7 @@ def main(args): wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) - wast2wasm.verbose = options.print_cmd + wast2json.verbose = options.print_cmd wasm_link.verbose = options.print_cmd wasm_objdump.verbose = options.print_cmd wasm_interp.verbose = options.print_cmd @@ -87,7 +87,7 @@ def main(args): basename = os.path.basename(filename) basename_noext = os.path.splitext(basename)[0] out_file = os.path.join(out_dir, basename_noext + '.json') - wast2wasm.RunWithArgs('--spec', '--debug-names', '--no-check', '-r', '-o', + wast2json.RunWithArgs('--debug-names', '--no-check', '-r', '-o', out_file, filename) wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file) diff --git a/test/too-many-arguments.txt b/test/too-many-arguments.txt index 9189b729..e3de62ec 100644 --- a/test/too-many-arguments.txt +++ b/test/too-many-arguments.txt @@ -1,4 +1,4 @@ -;;; EXE: %(wast2wasm)s +;;; EXE: %(wat2wasm)s ;;; FLAGS: foo.txt bar.txt ;;; ERROR: 1 (;; STDERR ;;; diff --git a/test/typecheck/bad-assertreturn-invoke-type-mismatch.txt b/test/typecheck/bad-assertreturn-invoke-type-mismatch.txt index 4766e227..95478b1e 100644 --- a/test/typecheck/bad-assertreturn-invoke-type-mismatch.txt +++ b/test/typecheck/bad-assertreturn-invoke-type-mismatch.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func (param i32) (result i32) get_local 0) (export "foo" 0)) diff --git a/test/typecheck/bad-assertreturn-type-mismatch.txt b/test/typecheck/bad-assertreturn-type-mismatch.txt index 0e81db7c..1cbf9f31 100644 --- a/test/typecheck/bad-assertreturn-type-mismatch.txt +++ b/test/typecheck/bad-assertreturn-type-mismatch.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func (param i32) (result i32) get_local 0) (export "foo" 0)) diff --git a/test/typecheck/bad-invoke-type-mismatch.txt b/test/typecheck/bad-invoke-type-mismatch.txt index c4e89dc2..56f32097 100644 --- a/test/typecheck/bad-invoke-type-mismatch.txt +++ b/test/typecheck/bad-invoke-type-mismatch.txt @@ -1,5 +1,5 @@ +;;; TOOL: wast2json ;;; ERROR: 1 -;;; FLAGS: --spec (module (func (param i32)) (export "foo" 0)) |