diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/tool-options.h | 19 | ||||
-rw-r--r-- | src/tools/wasm-as.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-dis.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-merge.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-metadce.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-opt.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-reduce.cpp | 8 | ||||
-rw-r--r-- | src/tools/wasm-split/wasm-split.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 10 |
11 files changed, 55 insertions, 14 deletions
diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h index bfa9a9b5c..f900d76ba 100644 --- a/src/tools/tool-options.h +++ b/src/tools/tool-options.h @@ -31,6 +31,7 @@ struct ToolOptions : public Options { PassOptions passOptions; bool quiet = false; + bool preserveTypeOrder = false; IRProfile profile = IRProfile::Normal; constexpr static const char* ToolOptionsCategory = "Tool options"; @@ -158,6 +159,16 @@ struct ToolOptions : public Options { [this](Options*, const std::string&) { passOptions.closedWorld = true; }) + .add( + "--preserve-type-order", + "", + "Preserve the order of types from the input (useful for debugging and " + "testing)", + ToolOptionsCategory, + Options::Arguments::Zero, + [&](Options* o, const std::string& arguments) { + preserveTypeOrder = true; + }) .add("--generate-stack-ir", "", "generate StackIR during writing", @@ -213,11 +224,17 @@ struct ToolOptions : public Options { return *this; } - void applyFeatures(Module& module) const { + void applyOptionsBeforeParse(Module& module) const { module.features.enable(enabledFeatures); module.features.disable(disabledFeatures); } + void applyOptionsAfterParse(Module& module) const { + if (!preserveTypeOrder) { + module.typeIndices.clear(); + } + } + virtual void addPassArg(const std::string& key, const std::string& value) { passOptions.arguments[key] = value; } diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp index a767e6908..73ae82134 100644 --- a/src/tools/wasm-as.cpp +++ b/src/tools/wasm-as.cpp @@ -107,13 +107,15 @@ int main(int argc, const char* argv[]) { auto input(read_file<std::string>(options.extra["infile"], Flags::Text)); Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); auto parsed = WATParser::parseModule(wasm, input); if (auto* err = parsed.getErr()) { Fatal() << err->msg; } + options.applyOptionsAfterParse(wasm); + if (options.extra["validate"] != "none") { if (options.debug) { std::cerr << "Validating..." << std::endl; diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 6809fa32a..d74790b2a 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -1445,7 +1445,7 @@ int main(int argc, const char* argv[]) { options.parse(argc, argv); Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); { if (options.debug) { @@ -1460,6 +1460,8 @@ int main(int argc, const char* argv[]) { } } + options.applyOptionsAfterParse(wasm); + if (!WasmValidator().validate(wasm)) { std::cout << wasm << '\n'; Fatal() << "error in validating input"; diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index f9f303359..1603736ce 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -64,7 +64,7 @@ int main(int argc, const char* argv[]) { std::cerr << "parsing binary..." << std::endl; } Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); try { ModuleReader().readBinary(options.extra["infile"], wasm, sourceMapFilename); } catch (ParseException& p) { @@ -82,6 +82,8 @@ int main(int argc, const char* argv[]) { Fatal() << "error in parsing wasm source mapping"; } + options.applyOptionsAfterParse(wasm); + // TODO: Validation. However, validating would mean that users are forced to // run with wasm-dis -all or such, to enable the features (unless the // features section is present, but that's rare in general). It would be diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 6b4e994ac..505e78349 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -196,7 +196,7 @@ int main(int argc, const char* argv[]) { auto writeOutput = outfile.size() > 0 || !emitBinary; Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); ModuleReader reader; // If we are not writing output then we definitely don't need to read debug // info. However, if we emit output then definitely load the names section so @@ -226,6 +226,8 @@ int main(int argc, const char* argv[]) { Fatal() << "error in parsing wasm source map"; } + options.applyOptionsAfterParse(wasm); + BYN_TRACE_WITH_TYPE("emscripten-dump", "Module before:\n"); BYN_DEBUG_WITH_TYPE("emscripten-dump", std::cerr << &wasm); diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 449f0cfdb..3de228350 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -695,7 +695,7 @@ Input source maps can be specified by adding an -ism option right after the modu currModule = laterInput.get(); } - options.applyFeatures(*currModule); + options.applyOptionsBeforeParse(*currModule); ModuleReader reader; try { @@ -705,6 +705,8 @@ Input source maps can be specified by adding an -ism option right after the modu Fatal() << "error in parsing wasm input: " << inputFile; } + options.applyOptionsAfterParse(*currModule); + if (options.passOptions.validate) { if (!WasmValidator().validate(*currModule)) { std::cout << *currModule << '\n'; diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp index 9cc06375e..41dcf6ad4 100644 --- a/src/tools/wasm-metadce.cpp +++ b/src/tools/wasm-metadce.cpp @@ -486,7 +486,7 @@ int main(int argc, const char* argv[]) { } Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); { if (options.debug) { @@ -502,6 +502,8 @@ int main(int argc, const char* argv[]) { } } + options.applyOptionsAfterParse(wasm); + if (options.passOptions.validate) { if (!WasmValidator().validate(wasm)) { std::cout << wasm << '\n'; diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp index d488171fb..3e1152179 100644 --- a/src/tools/wasm-opt.cpp +++ b/src/tools/wasm-opt.cpp @@ -243,7 +243,7 @@ int main(int argc, const char* argv[]) { options.parse(argc, argv); Module wasm; - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); BYN_TRACE("reading...\n"); @@ -294,6 +294,8 @@ int main(int argc, const char* argv[]) { "request for silly amounts of memory)"; } + options.applyOptionsAfterParse(wasm); + if (options.passOptions.validate) { if (!WasmValidator().validate(wasm, options.passOptions)) { exitOnInvalidWasm("error validating input"); diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index c276296ad..8d9858b78 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -362,6 +362,9 @@ struct Reducer void loadWorking() { module = std::make_unique<Module>(); + + toolOptions.applyOptionsBeforeParse(*module); + ModuleReader reader; try { reader.read(working, *module); @@ -371,15 +374,14 @@ struct Reducer Fatal() << "error in parsing working wasm binary"; } + toolOptions.applyOptionsAfterParse(*module); + // If there is no features section, assume we may need them all (without // this, a module with no features section but that uses e.g. atomics and // bulk memory would not work). if (!module->hasFeaturesSection) { module->features = FeatureSet::All; } - // Apply features the user passed on the commandline. - toolOptions.applyFeatures(*module); - builder = std::make_unique<Builder>(*module); setModule(module.get()); } diff --git a/src/tools/wasm-split/wasm-split.cpp b/src/tools/wasm-split/wasm-split.cpp index eed26f1e1..c1ec6052f 100644 --- a/src/tools/wasm-split/wasm-split.cpp +++ b/src/tools/wasm-split/wasm-split.cpp @@ -38,7 +38,7 @@ using namespace wasm; namespace { void parseInput(Module& wasm, const WasmSplitOptions& options) { - options.applyFeatures(wasm); + options.applyOptionsBeforeParse(wasm); ModuleReader reader; reader.setProfile(options.profile); try { @@ -52,6 +52,8 @@ void parseInput(Module& wasm, const WasmSplitOptions& options) { "request for silly amounts of memory)"; } + options.applyOptionsAfterParse(wasm); + if (options.passOptions.validate && !WasmValidator().validate(wasm)) { Fatal() << "error validating input"; } diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 286f89890..2c48e5be0 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -786,7 +786,9 @@ void AssertionEmitter::emit() { if (auto* mod = std::get_if<WASTModule>(&cmd)) { if (auto* w = std::get_if<std::shared_ptr<Module>>(mod)) { wasm = *w; - options.applyFeatures(*wasm); + // We have already done the parse, but we still do this to apply the + // features from the command line. + options.applyOptionsBeforeParse(*wasm); std::stringstream funcNameS; funcNameS << ASM_FUNC << i; std::stringstream moduleNameS; @@ -928,6 +930,7 @@ int main(int argc, const char* argv[]) { // is defined. if (binaryInput) { wasm = std::make_shared<Module>(); + options.applyOptionsBeforeParse(*wasm); ModuleReader reader; reader.read(input, *wasm, ""); } else { @@ -946,6 +949,9 @@ int main(int argc, const char* argv[]) { if (auto* mod = std::get_if<WASTModule>(&(*script)[0].cmd)) { if (auto* w = std::get_if<std::shared_ptr<Module>>(mod)) { wasm = *w; + // This isn't actually before the parse, but we can't apply the + // feature options any earlier. FIXME. + options.applyOptionsBeforeParse(*wasm); } } if (!wasm) { @@ -965,7 +971,7 @@ int main(int argc, const char* argv[]) { Fatal() << "error: modules with multiple tables are not supported yet."; } - options.applyFeatures(*wasm); + options.applyOptionsAfterParse(*wasm); if (options.passOptions.validate) { if (!WasmValidator().validate(*wasm)) { std::cout << *wasm << '\n'; |