diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-06-14 11:32:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-14 11:32:10 -0700 |
commit | 8f524e8f926b6993878f02334e730fe5f65096f6 (patch) | |
tree | 47c8121c1b9f2b90d42b673b2f14798a7b8681e8 /src/tools/s2wasm.cpp | |
parent | 24fa19071d309c59eee5c2bd966139eaab45b5ba (diff) | |
download | binaryen-8f524e8f926b6993878f02334e730fe5f65096f6.tar.gz binaryen-8f524e8f926b6993878f02334e730fe5f65096f6.tar.bz2 binaryen-8f524e8f926b6993878f02334e730fe5f65096f6.zip |
Add mode to wasm validator to check for web-environment constraints (#584)
In the web embedding, modules are not allowed to import or export
functions which have i64 params or return values. Add a mode to the
validator to check for this, and add flags to s2wasm and wasm-as to
enable or disable this check. Also add tests.
Diffstat (limited to 'src/tools/s2wasm.cpp')
-rw-r--r-- | src/tools/s2wasm.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index 54404c478..2ee094af4 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -32,10 +32,10 @@ using namespace wasm; int main(int argc, const char *argv[]) { bool ignoreUnknownSymbols = false; bool generateEmscriptenGlue = false; - bool validateOutput = true; std::string startFunction; std::vector<std::string> archiveLibraries; Options options("s2wasm", "Link .s file into .wast"); + options.extra["validate"] = "wasm"; options .add("--output", "-o", "Output file (stdout if not specified)", Options::Arguments::One, @@ -83,10 +83,14 @@ int main(int argc, const char *argv[]) { [&archiveLibraries](Options *o, const std::string &argument) { archiveLibraries.push_back(argument); }) - .add("--no-validate", "", "Disable validation of the output module", - Options::Arguments::Zero, - [&validateOutput](Options *, const std::string &) { - validateOutput = false; + .add("--validate", "-v", "Control validation of the output module", + Options::Arguments::One, + [](Options *o, const std::string &argument) { + if (argument != "web" && argument != "none" && argument != "wasm") { + std::cerr << "Valid arguments for --validate flag are 'wasm', 'web' and 'none'.\n"; + exit(1); + } + o->extra["validate"] = argument; }) .add_positional("INFILE", Options::Arguments::One, [](Options *o, const std::string &argument) { @@ -138,9 +142,12 @@ int main(int argc, const char *argv[]) { linker.emscriptenGlue(meta); } - if (options.debug) std::cerr << "Validating..." << std::endl; - if (validateOutput && !wasm::WasmValidator().validate(linker.getOutput().wasm)) { - Fatal() << "Error: linked module is not valid.\n"; + if (options.extra["validate"] != "none") { + if (options.debug) std::cerr << "Validating..." << std::endl; + if (!wasm::WasmValidator().validate(linker.getOutput().wasm, + options.extra["validate"] == "web")) { + Fatal() << "Error: linked module is not valid.\n"; + } } if (options.debug) std::cerr << "Printing..." << std::endl; |