summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-04-27 14:50:13 -0700
committerGitHub <noreply@github.com>2018-04-27 14:50:13 -0700
commita645da8fd22cea7789f07d4e0b88fdf38f9f5035 (patch)
tree646997ba66b01c6d73df8828cee70ecdb9faeec1 /src
parent7e8a47add58ebf5f39523fe70461aa7119ee490d (diff)
downloadbinaryen-a645da8fd22cea7789f07d4e0b88fdf38f9f5035.tar.gz
binaryen-a645da8fd22cea7789f07d4e0b88fdf38f9f5035.tar.bz2
binaryen-a645da8fd22cea7789f07d4e0b88fdf38f9f5035.zip
improve --extract-function (#1517)
Remove more of the unwanted stuff, and leave just an export to the function we are extracting. Then optimizations can do an effective cleanup.
Diffstat (limited to 'src')
-rw-r--r--src/passes/ExtractFunction.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/passes/ExtractFunction.cpp b/src/passes/ExtractFunction.cpp
index b91d2c406..7259f399d 100644
--- a/src/passes/ExtractFunction.cpp
+++ b/src/passes/ExtractFunction.cpp
@@ -26,19 +26,37 @@ namespace wasm {
struct ExtractFunction : public Pass {
void run(PassRunner* runner, Module* module) override {
- auto* leave = getenv("BYN_LEAVE");
+ auto* leave = getenv("BINARYEN_EXTRACT");
if (!leave) {
- std::cerr << "usage: set BYN_LEAVE in the env\n";
+ std::cerr << "usage: set BINARYEN_EXTRACT in the env\n";
abort();
}
Name LEAVE(leave);
- std::cerr << "keeping " << LEAVE << "\n";
+ std::cerr << "extracting " << LEAVE << "\n";
+ bool found = false;
for (auto& func : module->functions) {
if (func->name != LEAVE) {
- // wipe out the body
+ // wipe out all the contents
+ func->vars.clear();
func->body = module->allocator.alloc<Unreachable>();
+ } else {
+ found = true;
}
}
+ if (!found) {
+ std::cerr << "could not find the function to extract\n";
+ abort();
+ }
+ // clear data
+ module->memory.segments.clear();
+ module->table.segments.clear();
+ // leave just an export for the thing we want
+ module->exports.clear();
+ auto* export_ = new Export;
+ export_->name = LEAVE;
+ export_->value = LEAVE;
+ export_->kind = ExternalKind::Function;
+ module->addExport(export_);
}
};