summaryrefslogtreecommitdiff
path: root/src/passes/ExtractFunction.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-04-03 10:49:48 -0700
committerGitHub <noreply@github.com>2019-04-03 10:49:48 -0700
commit02198da745469104cb6ced60b37efa8d8a7f4464 (patch)
treef858c800d4ecfc2180a8a66e5bb86421ebeb82c8 /src/passes/ExtractFunction.cpp
parent29d638f9d298a9448996bcd3f50a9d51b7d200d9 (diff)
downloadbinaryen-02198da745469104cb6ced60b37efa8d8a7f4464.tar.gz
binaryen-02198da745469104cb6ced60b37efa8d8a7f4464.tar.bz2
binaryen-02198da745469104cb6ced60b37efa8d8a7f4464.zip
Add a mechanism to pass arguments to passes (#1941)
This allows wasm-opt --pass-arg=KEY:VALUE where KEY and VALUE are strings. It is then added to passOptions.arguments, where passes can read it. This is used in ExtractFunction instead of an env var.
Diffstat (limited to 'src/passes/ExtractFunction.cpp')
-rw-r--r--src/passes/ExtractFunction.cpp22
1 files changed, 9 insertions, 13 deletions
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_);
}