summaryrefslogtreecommitdiff
path: root/src/passes/ExtractFunction.cpp
diff options
context:
space:
mode:
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_);
}