summaryrefslogtreecommitdiff
path: root/src/tools/tool-options.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/tool-options.h')
-rw-r--r--src/tools/tool-options.h167
1 files changed, 90 insertions, 77 deletions
diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h
index 671085a4e..5b09b8d23 100644
--- a/src/tools/tool-options.h
+++ b/src/tools/tool-options.h
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include "ir/module-utils.h"
#include "support/command-line.h"
#include "pass.h"
@@ -30,92 +31,104 @@ struct ToolOptions : public Options {
: Options(command, description) {
(*this)
.add("--mvp-features", "-mvp", "Disable all non-MVP features",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features = FeatureSet::MVP;
- })
- .add("--all-features", "-all", "Enable all features (default)",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features = FeatureSet::All;
- })
- .add("--enable-sign-ext", "", "Enable sign extension operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setSignExt();
- })
- .add("--disable-sign-ext", "", "Disable sign extension operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setSignExt(false);
- })
- .add("--enable-threads", "", "Enable atomic operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setAtomics();
- })
- .add("--disable-threads", "", "Disable atomic operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setAtomics(false);
- })
- .add("--enable-mutable-globals", "", "Enable mutable globals",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setMutableGlobals();
- })
- .add("--disable-mutable-globals", "", "Disable mutable globals",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setMutableGlobals(false);
- })
- .add("--enable-nontrapping-float-to-int", "",
- "Enable nontrapping float-to-int operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setTruncSat();
- })
- .add("--disable-nontrapping-float-to-int", "",
- "Disable nontrapping float-to-int operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setTruncSat(false);
+ Arguments::Zero,
+ [this](Options*, const std::string&) {
+ hasFeatureOptions = true;
+ passOptions.features.makeMVP();
+ enabledFeatures.makeMVP();
+ disabledFeatures.setAll();
})
- .add("--enable-simd", "",
- "Enable SIMD operations and types",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setSIMD();
+ .add("--all-features", "-all", "Enable all features "
+ "(default if there is no target features section"
+ " or if any feature options are provided)",
+ Arguments::Zero,
+ [this](Options*, const std::string&) {
+ hasFeatureOptions = true;
+ passOptions.features.setAll();
+ enabledFeatures.setAll();
+ disabledFeatures.makeMVP();
})
- .add("--disable-simd", "",
- "Disable SIMD operations and types",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setSIMD(false);
- })
- .add("--enable-bulk-memory", "",
- "Enable bulk memory operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setBulkMemory();
- })
- .add("--disable-bulk-memory", "",
- "Disable bulk memory operations",
- Options::Arguments::Zero,
- [this](Options *o, const std::string& arguments) {
- passOptions.features.setBulkMemory(false);
- })
- .add("--no-validation", "-n", "Disables validation, assumes inputs are correct",
+ .add("--detect-features", "",
+ "Use features from the target features section"
+ "(default if there is a target features section"
+ " and no feature options are provided)",
+ Arguments::Zero,
+ [this](Options*, const std::string&) {
+ hasFeatureOptions = true;
+ detectFeatures = true;
+ enabledFeatures.makeMVP();
+ disabledFeatures.makeMVP();
+ });
+ (*this)
+ .addFeature("sign-ext", "sign extension operations",
+ FeatureSet::SignExt)
+ .addFeature("threads", "atomic operations",
+ FeatureSet::Atomics)
+ .addFeature("mutable-globals", "mutable globals",
+ FeatureSet::MutableGlobals)
+ .addFeature("nontrapping-float-to-int",
+ "nontrapping float-to-int operations",
+ FeatureSet::TruncSat)
+ .addFeature("simd", "SIMD operations and types",
+ FeatureSet::SIMD)
+ .addFeature("bulk-memory", "bulk memory operations",
+ FeatureSet::BulkMemory)
+ .add("--no-validation", "-n",
+ "Disables validation, assumes inputs are correct",
Options::Arguments::Zero,
[this](Options* o, const std::string& argument) {
passOptions.validate = false;
});
- ;
}
- FeatureSet getFeatures() const {
- return passOptions.features;
+ ToolOptions& addFeature(const std::string& name,
+ const std::string& description,
+ FeatureSet::Feature feature) {
+ (*this)
+ .add(std::string("--enable-") + name, "",
+ std::string("Enable ") + description, Arguments::Zero,
+ [=](Options*, const std::string&) {
+ hasFeatureOptions = true;
+ passOptions.features.set(feature, true);
+ enabledFeatures.set(feature, true);
+ disabledFeatures.set(feature, false);
+ })
+
+ .add(std::string("--disable-") + name, "",
+ std::string("Disable ") + description, Arguments::Zero,
+ [=](Options*, const std::string&) {
+ hasFeatureOptions = true;
+ passOptions.features.set(feature, false);
+ enabledFeatures.set(feature, false);
+ disabledFeatures.set(feature, true);
+ });
+ return *this;
}
+
+ void calculateFeatures(const Module& module) {
+ FeatureSet wasmFeatures;
+ bool wasmHasFeatures =
+ ModuleUtils::readFeaturesSection(module, wasmFeatures);
+
+ if (hasFeatureOptions) {
+ if (detectFeatures) {
+ wasmFeatures.enable(enabledFeatures);
+ wasmFeatures.disable(disabledFeatures);
+ passOptions.features = wasmFeatures;
+ } else if (!(wasmFeatures <= passOptions.features)) {
+ Fatal() << "module uses features not explicitly specified, "
+ << "use --detect-features to resolve";
+ }
+ } else if (wasmHasFeatures) {
+ passOptions.features = wasmFeatures;
+ }
+ }
+
+private:
+ bool hasFeatureOptions = false;
+ bool detectFeatures = false;
+ FeatureSet enabledFeatures = FeatureSet::MVP;
+ FeatureSet disabledFeatures = FeatureSet::MVP;
};
} // namespace wasm