Skip to content

Commit c57dd1f

Browse files
authored
wasm-reduce: default to -all, and make it customizable (#3492)
This goes back to the downsides of #2813, but that seems unavoidable as without this, testcases without the features section but that use features did not work. This PR at least makes it easy to customize the flags send to the commands. See also #3393 (comment)
1 parent e2dc4c3 commit c57dd1f

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/tools/wasm-reduce.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ std::string GetLastErrorStdStr() {
7171
#endif
7272
using namespace wasm;
7373

74-
// a timeout on every execution of the command
75-
size_t timeout = 2;
74+
// A timeout on every execution of the command.
75+
static size_t timeout = 2;
76+
77+
// A string of feature flags and other things to pass while reducing. The
78+
// default of enabling all features should work in most cases.
79+
static std::string extraFlags = "-all";
7680

7781
struct ProgramResult {
7882
int code;
@@ -282,14 +286,12 @@ struct Reducer
282286
// compensated for), and without
283287
for (auto pass : passes) {
284288
std::string currCommand = Path::getBinaryenBinaryTool("wasm-opt") + " ";
285-
currCommand += working + " --detect-features -o " + test + " " + pass;
289+
currCommand += working + " -o " + test + " " + pass + " " + extraFlags;
286290
if (debugInfo) {
287291
currCommand += " -g ";
288292
}
289293
if (!binary) {
290-
currCommand += " -S --all-features ";
291-
} else {
292-
currCommand += " --detect-features ";
294+
currCommand += " -S ";
293295
}
294296
if (verbose) {
295297
std::cerr << "| trying pass command: " << currCommand << "\n";
@@ -1153,6 +1155,15 @@ int main(int argc, const char* argv[]) {
11531155
timeout = atoi(argument.c_str());
11541156
std::cout << "|applying timeout: " << timeout << "\n";
11551157
})
1158+
.add("--extra-flags",
1159+
"-ef",
1160+
"Extra commandline flags to pass to wasm-opt while reducing. "
1161+
"(default: --enable-all)",
1162+
Options::Arguments::One,
1163+
[&](Options* o, const std::string& argument) {
1164+
extraFlags = argument;
1165+
std::cout << "|applying extraFlags: " << extraFlags << "\n";
1166+
})
11561167
.add_positional(
11571168
"INFILE",
11581169
Options::Arguments::One,
@@ -1230,12 +1241,10 @@ int main(int argc, const char* argv[]) {
12301241
"(read-written) binary\n";
12311242
{
12321243
// read and write it
1233-
auto cmd =
1234-
Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -o " + test;
1244+
auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -o " +
1245+
test + " " + extraFlags;
12351246
if (!binary) {
1236-
cmd += " -S --all-features";
1237-
} else {
1238-
cmd += " --detect-features";
1247+
cmd += " -S ";
12391248
}
12401249
ProgramResult readWrite(cmd);
12411250
if (readWrite.failed()) {

0 commit comments

Comments
 (0)