Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/passes/RemoveExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
//
// --remove-exports=__*
//
// That will remove all exports with names like "__foo" and "__bar".
// In this case we will remove all exports with names like "__foo" and "__bar".
//
// Exports can also be specified as a comma-separated list, and can be a
// response file.
//

#include "pass.h"
#include "support/file.h"
#include "support/string.h"
#include "wasm.h"

Expand All @@ -32,13 +36,21 @@ namespace {

struct RemoveExports : public Pass {
void run(Module* module) override {
std::string pattern =
std::string param =
getArgument(name, "Usage usage: wasm-opt --" + name + "=WILDCARD");

param = String::trim(read_possible_response_file(param));

String::Split patterns(param, String::Split::NewLineOr(","));
patterns = handleBracketingOperators(patterns);
Comment on lines +42 to +45
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cool that we already have these functions!


std::vector<Name> toRemove;
for (auto& exp : module->exports) {
if (String::wildcardMatch(pattern, exp->name.toString())) {
toRemove.push_back(exp->name);
for (auto& pattern : patterns) {
if (String::wildcardMatch(pattern, exp->name.toString())) {
toRemove.push_back(exp->name);
break;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/lit/passes/remove-exports-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
bar
37 changes: 37 additions & 0 deletions test/lit/passes/remove-exports-file.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --remove-exports=@%S/remove-exports-file.txt -all -S -o - | filecheck %s

;; Test a response file as the input to this pass. foo and bar will be removed.
(module
;; CHECK: (type $0 (func))

;; CHECK: (export "keep" (func $keep))

;; CHECK: (func $foo (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo (export "foo")
(drop (i32.const 1))
)

;; CHECK: (func $bar (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $bar (export "bar")
(drop (i32.const 2))
)

;; CHECK: (func $keep (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 3)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $keep (export "keep")
(drop (i32.const 3))
)
)
38 changes: 38 additions & 0 deletions test/lit/passes/remove-exports-list.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt "--remove-exports=foo<x,y>,bar" -all -S -o - | filecheck %s

;; The two exports mentioned will be removed (note the handling of comma
;; separation, taking into account bracketing). The other will remain.
(module
;; CHECK: (type $0 (func))

;; CHECK: (export "keep" (func $keep))

;; CHECK: (func $"foo<x,y>" (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $"foo<x,y>" (export "foo<x,y>")
(drop (i32.const 1))
)

;; CHECK: (func $bar (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $bar (export "bar")
(drop (i32.const 2))
)

;; CHECK: (func $keep (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 3)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $keep (export "keep")
(drop (i32.const 3))
)
)
1 change: 0 additions & 1 deletion test/lit/passes/remove-exports.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.

;; RUN: foreach %s %t wasm-opt "--remove-exports=__*" -all -S -o - | filecheck %s

Expand Down
Loading