@@ -83,6 +83,9 @@ static size_t timeout = 2;
83
83
// default of enabling all features should work in most cases.
84
84
static std::string extraFlags = " -all" ;
85
85
86
+ // Whether to save all intermediate working files as we go.
87
+ static bool saveAllWorkingFiles = false ;
88
+
86
89
struct ProgramResult {
87
90
int code;
88
91
std::string output;
@@ -231,6 +234,11 @@ ProgramResult expected;
231
234
// case we may try again but much later.
232
235
static std::unordered_set<Name> functionsWeTriedToRemove;
233
236
237
+ // The index of the working file we save, when saveAllWorkingFiles. We must
238
+ // store this globally so that the difference instances of Reducer do not
239
+ // overlap.
240
+ static size_t workingFileIndex = 0 ;
241
+
234
242
struct Reducer
235
243
: public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor<Reducer>>> {
236
244
std::string command, test, working;
@@ -322,7 +330,7 @@ struct Reducer
322
330
if (ProgramResult (command) == expected) {
323
331
std::cerr << " | command \" " << currCommand
324
332
<< " \" succeeded, reduced size to " << newSize << ' \n ' ;
325
- copy_file (test, working );
333
+ applyTestToWorking ( );
326
334
more = true ;
327
335
oldSize = newSize;
328
336
}
@@ -335,6 +343,16 @@ struct Reducer
335
343
}
336
344
}
337
345
346
+ // Apply the test file to the working file, after we saw that it successfully
347
+ // reduced the testcase.
348
+ void applyTestToWorking () {
349
+ copy_file (test, working);
350
+
351
+ if (saveAllWorkingFiles) {
352
+ copy_file (working, working + ' .' + std::to_string (workingFileIndex++));
353
+ }
354
+ }
355
+
338
356
// does one pass of slow and destructive reduction. returns whether it
339
357
// succeeded or not
340
358
// the criterion here is a logical change in the program. this may actually
@@ -471,7 +489,7 @@ struct Reducer
471
489
472
490
void noteReduction (size_t amount = 1 ) {
473
491
reduced += amount;
474
- copy_file (test, working );
492
+ applyTestToWorking ( );
475
493
}
476
494
477
495
// tests a reduction on an arbitrary child
@@ -1302,6 +1320,15 @@ int main(int argc, const char* argv[]) {
1302
1320
extraFlags = argument;
1303
1321
std::cout << " |applying extraFlags: " << extraFlags << " \n " ;
1304
1322
})
1323
+ .add (" --save-all-working" ,
1324
+ " -saw" ,
1325
+ " Save all intermediate working files, as $WORKING.0, .1, .2 etc" ,
1326
+ WasmReduceOption,
1327
+ Options::Arguments::Zero,
1328
+ [&](Options* o, const std::string& argument) {
1329
+ saveAllWorkingFiles = true ;
1330
+ std::cout << " |saving all intermediate working files\n " ;
1331
+ })
1305
1332
.add_positional (
1306
1333
" INFILE" ,
1307
1334
Options::Arguments::One,
0 commit comments