diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/optimization-options.h | 11 | ||||
-rw-r--r-- | src/tools/tool-options.h (renamed from src/tools/feature-options.h) | 9 | ||||
-rw-r--r-- | src/tools/wasm-shell.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 10 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 6 |
5 files changed, 27 insertions, 13 deletions
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h index 7849be375..53fd60e4d 100644 --- a/src/tools/optimization-options.h +++ b/src/tools/optimization-options.h @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "feature-options.h" +#include "tool-options.h" // // Shared optimization options for commandline tools @@ -22,12 +22,12 @@ namespace wasm { -struct OptimizationOptions : public FeatureOptions { +struct OptimizationOptions : public ToolOptions { static constexpr const char* DEFAULT_OPT_PASSES = "O"; std::vector<std::string> passes; - OptimizationOptions(const std::string& command, const std::string& description) : FeatureOptions(command, description) { + OptimizationOptions(const std::string& command, const std::string& description) : ToolOptions(command, description) { (*this).add("", "-O", "execute default optimization passes", Options::Arguments::Zero, [this](Options*, const std::string&) { @@ -92,11 +92,6 @@ struct OptimizationOptions : public FeatureOptions { [this](Options* o, const std::string& argument) { passOptions.shrinkLevel = atoi(argument.c_str()); }) - .add("--no-validation", "-n", "Disables validation, assumes inputs are correct", - Options::Arguments::Zero, - [this](Options* o, const std::string& argument) { - passOptions.validate = false; - }) .add("--ignore-implicit-traps", "-iit", "Optimize under the helpful assumption that no surprising traps occur (from load, div/mod, etc.)", Options::Arguments::Zero, [this](Options*, const std::string&) { diff --git a/src/tools/feature-options.h b/src/tools/tool-options.h index 282aa4d4b..9aff8e619 100644 --- a/src/tools/feature-options.h +++ b/src/tools/tool-options.h @@ -23,10 +23,10 @@ namespace wasm { -struct FeatureOptions : public Options { +struct ToolOptions : public Options { PassOptions passOptions; - FeatureOptions(const std::string& command, const std::string& description) + ToolOptions(const std::string& command, const std::string& description) : Options(command, description) { (*this) .add("--mvp-features", "-mvp", "Disable all non-MVP features", @@ -83,6 +83,11 @@ struct FeatureOptions : public Options { [this](Options *o, const std::string& arguments) { passOptions.features.setSIMD(false); }) + .add("--no-validation", "-n", "Disables validation, assumes inputs are correct", + Options::Arguments::Zero, + [this](Options* o, const std::string& argument) { + passOptions.validate = false; + }); ; } diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index d8cd11f41..dcb1b2725 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -23,7 +23,6 @@ #include <memory> #include "execution-results.h" -#include "feature-options.h" #include "pass.h" #include "shell-interface.h" #include "support/file.h" @@ -31,6 +30,7 @@ #include "wasm-printing.h" #include "wasm-s-parser.h" #include "wasm-validator.h" +#include "tool-options.h" using namespace cashew; using namespace wasm; @@ -233,7 +233,7 @@ int main(int argc, const char* argv[]) { Name entry; std::set<size_t> skipped; - FeatureOptions options("wasm-shell", "Execute .wast files"); + ToolOptions options("wasm-shell", "Execute .wast files"); options .add( "--entry", "-e", "Call the entry point after parsing the module", 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); diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 0b07be802..f1ccb2cfa 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1072,6 +1072,12 @@ void FunctionValidator::visitFunction(Function* curr) { if (curr->imported()) { shouldBeTrue(curr->type.is(), curr->name, "imported functions must have a function type"); } + // validate optional local names + std::set<Name> seen; + for (auto& pair : curr->localNames) { + Name name = pair.second; + shouldBeTrue(seen.insert(name).second, name, "local names must be unique"); + } } static bool checkOffset(Expression* curr, Address add, Address max) { |