summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-07-26 15:14:45 -0700
committerGitHub <noreply@github.com>2022-07-26 15:14:45 -0700
commit61483f5e77e6a6b1370e60044ebb20b22b6abb71 (patch)
tree1af7f009d7436b02f842feed0069ffb32c3dbc78 /src
parentf7203a02ae85fff2075ead73246c15ab1dbe8640 (diff)
downloadbinaryen-61483f5e77e6a6b1370e60044ebb20b22b6abb71.tar.gz
binaryen-61483f5e77e6a6b1370e60044ebb20b22b6abb71.tar.bz2
binaryen-61483f5e77e6a6b1370e60044ebb20b22b6abb71.zip
wasm-reduce: Apply commandline features (#4833)
This lets wasm-reduce --enable-FOO work. Usually this is not needed as we do enable all features by default, but sometimes it is nice to disable features (e.g. to avoid reducing into a testcase that uses something the original wasm did not use).
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-reduce.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index 28cc77e95..52a4be2d4 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -232,6 +232,7 @@ struct Reducer
: public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor<Reducer>>> {
std::string command, test, working;
bool binary, deNan, verbose, debugInfo;
+ ToolOptions& toolOptions;
// test is the file we write to that the command will operate on
// working is the current temporary state, the reduction so far
@@ -241,9 +242,11 @@ struct Reducer
bool binary,
bool deNan,
bool verbose,
- bool debugInfo)
+ bool debugInfo,
+ ToolOptions& toolOptions)
: command(command), test(test), working(working), binary(binary),
- deNan(deNan), verbose(verbose), debugInfo(debugInfo) {}
+ deNan(deNan), verbose(verbose), debugInfo(debugInfo),
+ toolOptions(toolOptions) {}
// runs passes in order to reduce, until we can't reduce any more
// the criterion here is wasm binary size
@@ -358,12 +361,16 @@ struct Reducer
std::cerr << '\n';
Fatal() << "error in parsing working wasm binary";
}
+
// 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 = make_unique<Builder>(*module);
setModule(module.get());
}
@@ -1388,7 +1395,8 @@ int main(int argc, const char* argv[]) {
bool stopping = false;
while (1) {
- Reducer reducer(command, test, working, binary, deNan, verbose, debugInfo);
+ Reducer reducer(
+ command, test, working, binary, deNan, verbose, debugInfo, options);
// run binaryen optimization passes to reduce. passes are fast to run
// and can often reduce large amounts of code efficiently, as opposed