From 119525ea6078c9af697de0038407ab541f3d4c12 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 23 Jan 2019 16:15:38 -0800 Subject: Validate unique local names, and use validation in wasm2js. Fixes #1885 (#1886) * Also fixes some bugs in wasm2js tests that did not validate. * Rename FeatureOptions => ToolOptions, as they now contain all the basic stuff each tool needs for commandline options (validation yes or no, and which features if so). --- src/tools/wasm2js.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/tools/wasm2js.cpp') diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 762a89985..277a4e2c9 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -23,13 +23,14 @@ #include "support/file.h" #include "wasm-s-parser.h" #include "wasm2js.h" +#include "tool-options.h" using namespace cashew; using namespace wasm; int main(int argc, const char *argv[]) { Wasm2JSBuilder::Flags builderFlags; - Options options("wasm2js", "Transform .wasm/.wast files to asm.js"); + ToolOptions options("wasm2js", "Transform .wasm/.wast files to asm.js"); options .add("--output", "-o", "Output file (stdout if not specified)", Options::Arguments::One, @@ -97,6 +98,13 @@ int main(int argc, const char *argv[]) { Fatal() << "error in building module, std::bad_alloc (possibly invalid request for silly amounts of memory)"; } + if (options.passOptions.validate) { + if (!WasmValidator().validate(wasm, options.getFeatures())) { + WasmPrinter::printModule(&wasm); + Fatal() << "error in validating input"; + } + } + if (options.debug) std::cerr << "asming..." << std::endl; Wasm2JSBuilder wasm2js(builderFlags); asmjs = wasm2js.processWasm(&wasm); -- cgit v1.2.3