diff options
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 577a460cb..8da42f9cd 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -17,6 +17,7 @@ #include <chrono> #include <sstream> +#include <support/colors.h> #include <passes/passes.h> #include <pass.h> #include <wasm-validator.h> @@ -111,7 +112,9 @@ void PassRunner::addDefaultOptimizationPasses() { } void PassRunner::addDefaultFunctionOptimizationPasses() { - add("dce"); + if (!options.debugInfo) { // debug info must be preserved, do not dce it + add("dce"); + } add("remove-unused-brs"); add("remove-unused-names"); add("optimize-instructions"); @@ -147,6 +150,17 @@ void PassRunner::addDefaultGlobalOptimizationPasses() { add("memory-packing"); } +static void dumpWast(Name name, Module* wasm) { + // write out the wast + Colors::disable(); + static int counter = 0; + std::stringstream text; + WasmPrinter::printModule(wasm, text); + FILE* f = fopen((std::string("byn-") + std::to_string(counter++) + "-" + name.str + ".wast").c_str(), "w"); + fputs(text.str().c_str(), f); + fclose(f); +} + void PassRunner::run() { // BINARYEN_PASS_DEBUG is a convenient commandline way to log out the toplevel passes, their times, // and validate between each pass. @@ -161,6 +175,9 @@ void PassRunner::run() { for (auto pass : passes) { padding = std::max(padding, pass->name.size()); } + if (passDebug >= 3) { + dumpWast("before", wasm); + } for (auto* pass : passes) { // ignoring the time, save a printout of the module before, in case this pass breaks it, so we can print the before and after std::stringstream moduleBefore; @@ -195,6 +212,9 @@ void PassRunner::run() { } abort(); } + if (passDebug >= 3) { + dumpWast(pass->name, wasm); + } } std::cerr << "[PassRunner] passes took " << totalTime.count() << " seconds." << std::endl; // validate |