summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/Strip.cpp34
-rw-r--r--src/passes/pass.cpp4
-rw-r--r--src/passes/passes.h3
3 files changed, 29 insertions, 12 deletions
diff --git a/src/passes/Strip.cpp b/src/passes/Strip.cpp
index d2ebbe129..8ab712cb1 100644
--- a/src/passes/Strip.cpp
+++ b/src/passes/Strip.cpp
@@ -15,10 +15,12 @@
*/
//
-// Similar to strip-ing a native binary, this removes debug info
-// and related things like source map URLs, names section, etc.
+// Similar to strip-ing a native binary, this family of passes can
+// removes debug info and other things.
//
+#include <functional>
+
#include "wasm.h"
#include "wasm-binary.h"
#include "pass.h"
@@ -28,6 +30,12 @@ using namespace std;
namespace wasm {
struct Strip : public Pass {
+ // A function that returns true if the method should be removed.
+ typedef std::function<bool (UserSection&)> Decider;
+ Decider decider;
+
+ Strip(Decider decider) : decider(decider) {}
+
void run(PassRunner* runner, Module* module) override {
// Remove name and debug sections.
auto& sections = module->userSections;
@@ -35,12 +43,7 @@ struct Strip : public Pass {
std::remove_if(
sections.begin(),
sections.end(),
- [&](const UserSection& curr) {
- return curr.name == BinaryConsts::UserSections::Name ||
- curr.name == BinaryConsts::UserSections::SourceMapUrl ||
- curr.name.find(".debug") == 0 ||
- curr.name.find("reloc..debug") == 0;
- }
+ decider
),
sections.end()
);
@@ -53,8 +56,19 @@ struct Strip : public Pass {
}
};
-Pass *createStripPass() {
- return new Strip();
+Pass *createStripDebugPass() {
+ return new Strip([&](const UserSection& curr) {
+ return curr.name == BinaryConsts::UserSections::Name ||
+ curr.name == BinaryConsts::UserSections::SourceMapUrl ||
+ curr.name.find(".debug") == 0 ||
+ curr.name.find("reloc..debug") == 0;
+ });
+}
+
+Pass *createStripProducersPass() {
+ return new Strip([&](const UserSection& curr) {
+ return curr.name == BinaryConsts::UserSections::Producers;
+ });
}
} // namespace wasm
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index cae69860a..2872575c2 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -133,7 +133,9 @@ void PassRegistry::registerPasses() {
registerPass("souperify-single-use", "emit Souper IR in text form (single-use nodes only)", createSouperifySingleUsePass);
registerPass("spill-pointers", "spill pointers to the C stack (useful for Boehm-style GC)", createSpillPointersPass);
registerPass("ssa", "ssa-ify variables so that they have a single assignment", createSSAifyPass);
- registerPass("strip", "strip debug info (including the names section)", createStripPass);
+ registerPass("strip", "deprecated; same as strip-debug", createStripDebugPass);
+ registerPass("strip-debug", "strip debug info (including the names section)", createStripDebugPass);
+ registerPass("strip-producers", "strip the wasm producers section", createStripProducersPass);
registerPass("trap-mode-clamp", "replace trapping operations with clamping semantics", createTrapModeClamp);
registerPass("trap-mode-js", "replace trapping operations with js semantics", createTrapModeJS);
registerPass("untee", "removes local.tees, replacing them with sets and gets", createUnteePass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index b04303429..15493f313 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -84,7 +84,8 @@ Pass* createSimplifyLocalsNoNestingPass();
Pass* createSimplifyLocalsNoTeePass();
Pass* createSimplifyLocalsNoStructurePass();
Pass* createSimplifyLocalsNoTeeNoStructurePass();
-Pass* createStripPass();
+Pass* createStripDebugPass();
+Pass* createStripProducersPass();
Pass* createSouperifyPass();
Pass* createSouperifySingleUsePass();
Pass* createSpillPointersPass();