From 996262dcdb88388717aab72bd8f37841aaabb24c Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 10 Jun 2016 13:08:58 -0700 Subject: s2wasm: Validate the result module (#574) Add an s2wasm option `--no-validate` to disable validation for debugging purposes. Also fix several validation errors by adding calls to `finalize()` after creating expressions, and ensuring that an import is created earlier in `Linker::getImportThunk`. --- src/tools/s2wasm.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/tools/s2wasm.cpp') diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index a6bbdea18..54404c478 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -24,6 +24,7 @@ #include "s2wasm.h" #include "wasm-linker.h" #include "wasm-printing.h" +#include "wasm-validator.h" using namespace cashew; using namespace wasm; @@ -31,6 +32,7 @@ using namespace wasm; int main(int argc, const char *argv[]) { bool ignoreUnknownSymbols = false; bool generateEmscriptenGlue = false; + bool validateOutput = true; std::string startFunction; std::vector archiveLibraries; Options options("s2wasm", "Link .s file into .wast"); @@ -81,6 +83,11 @@ 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_positional("INFILE", Options::Arguments::One, [](Options *o, const std::string &argument) { o->extra["infile"] = argument; @@ -131,10 +138,16 @@ 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.debug) std::cerr << "Printing..." << std::endl; Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); WasmPrinter::printModule(&linker.getOutput().wasm, output.getStream()); output << meta.str(); if (options.debug) std::cerr << "Done." << std::endl; + return 0; } -- cgit v1.2.3