summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pass.h9
-rw-r--r--src/passes/ExtractFunction.cpp22
-rw-r--r--src/tools/optimization-options.h11
3 files changed, 29 insertions, 13 deletions
diff --git a/src/pass.h b/src/pass.h
index 9ef159d7d..6116a9cca 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -76,6 +76,8 @@ struct PassOptions {
bool debugInfo = false;
// Which wasm features to accept, and be allowed to use.
FeatureSet features = FeatureSet::All;
+ // Arbitrary string arguments from the commandline, which we forward to passes.
+ std::map<std::string, std::string> arguments;
void setDefaultOptimizationOptions() {
// -Os is our default
@@ -92,6 +94,13 @@ struct PassOptions {
static PassOptions getWithoutOptimization() {
return PassOptions(); // defaults are to not optimize
}
+
+ std::string getArgument(std::string key, std::string errorTextIfMissing) {
+ if (arguments.count(key) == 0) {
+ Fatal() << errorTextIfMissing;
+ }
+ return arguments[key];
+ }
};
//
diff --git a/src/passes/ExtractFunction.cpp b/src/passes/ExtractFunction.cpp
index 7259f399d..8a97ced8e 100644
--- a/src/passes/ExtractFunction.cpp
+++ b/src/passes/ExtractFunction.cpp
@@ -23,22 +23,18 @@
namespace wasm {
-
struct ExtractFunction : public Pass {
void run(PassRunner* runner, Module* module) override {
- auto* leave = getenv("BINARYEN_EXTRACT");
- if (!leave) {
- std::cerr << "usage: set BINARYEN_EXTRACT in the env\n";
- abort();
- }
- Name LEAVE(leave);
- std::cerr << "extracting " << LEAVE << "\n";
+ Name name = runner->options.getArgument("extract", "ExtractFunction usage: wasm-opt --pass-arg=extract:FUNCTION_NAME");
+ std::cerr << "extracting " << name << "\n";
bool found = false;
for (auto& func : module->functions) {
- if (func->name != LEAVE) {
- // wipe out all the contents
+ if (func->name != name) {
+ // Turn it into an import.
+ func->module = "env";
+ func->base = func->name;
func->vars.clear();
- func->body = module->allocator.alloc<Unreachable>();
+ func->body = nullptr;
} else {
found = true;
}
@@ -53,8 +49,8 @@ struct ExtractFunction : public Pass {
// leave just an export for the thing we want
module->exports.clear();
auto* export_ = new Export;
- export_->name = LEAVE;
- export_->value = LEAVE;
+ export_->name = name;
+ export_->value = name;
export_->kind = ExternalKind::Function;
module->addExport(export_);
}
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h
index 4b8bfc139..dfc61b0e3 100644
--- a/src/tools/optimization-options.h
+++ b/src/tools/optimization-options.h
@@ -101,6 +101,17 @@ struct OptimizationOptions : public ToolOptions {
Options::Arguments::Zero,
[this](Options*, const std::string&) {
passOptions.lowMemoryUnused = true;
+ })
+ .add("--pass-arg", "-pa", "An argument passed along to optimization passes being run. Must be in the form KEY:VALUE",
+ Options::Arguments::N,
+ [this](Options*, const std::string& argument) {
+ auto colon = argument.find(':');
+ if (colon == std::string::npos) {
+ Fatal() << "--pass-arg value must be in the form of KEY:VALUE";
+ }
+ auto key = argument.substr(0, colon);
+ auto value = argument.substr(colon + 1);
+ passOptions.arguments[key] = value;
});
// add passes in registry
for (const auto& p : PassRegistry::get()->getRegisteredNames()) {