Skip to content

Commit 8bdfcf0

Browse files
committed
improve pass debug tools
1 parent acac2ca commit 8bdfcf0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/passes/pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ void PassRunner::addDefaultGlobalOptimizationPasses() {
138138
}
139139

140140
void PassRunner::run() {
141-
if (options.debug) {
141+
static int passDebug = getenv("BINARYEN_PASS_DEBUG") ? atoi(getenv("BINARYEN_PASS_DEBUG")) : 0;
142+
if (options.debug || passDebug) {
142143
// for debug logging purposes, run each pass in full before running the other
143144
auto totalTime = std::chrono::duration<double>(0);
144145
size_t padding = 0;
145146
std::cerr << "[PassRunner] running passes..." << std::endl;
146147
for (auto pass : passes) {
147148
padding = std::max(padding, pass->name.size());
148149
}
149-
bool passDebug = getenv("BINARYEN_PASS_DEBUG") && getenv("BINARYEN_PASS_DEBUG")[0] != '0';
150150
for (auto* pass : passes) {
151151
// ignoring the time, save a printout of the module before, in case this pass breaks it, so we can print the before and after
152152
std::stringstream moduleBefore;
153-
if (passDebug) {
153+
if (passDebug >= 2) {
154154
WasmPrinter::printModule(wasm, moduleBefore);
155155
}
156156
// prepare to run
@@ -174,10 +174,10 @@ void PassRunner::run() {
174174
// validate, ignoring the time
175175
std::cerr << "[PassRunner] (validating)\n";
176176
if (!WasmValidator().validate(*wasm, false, options.validateGlobally)) {
177-
if (passDebug) {
177+
if (passDebug >= 2) {
178178
std::cerr << "Last pass (" << pass->name << ") broke validation. Here is the module before: \n" << moduleBefore.str() << "\n";
179179
} else {
180-
std::cerr << "Last pass (" << pass->name << ") broke validation. Run with BINARYEN_PASS_DEBUG=1 in the env to see the earlier state\n";
180+
std::cerr << "Last pass (" << pass->name << ") broke validation. Run with BINARYEN_PASS_DEBUG=2 in the env to see the earlier state\n";
181181
}
182182
abort();
183183
}

0 commit comments

Comments
 (0)