Skip to content

Commit d1ee405

Browse files
authored
RemoveExports: Support comma separation and a response file (#8674)
Helps #7976
1 parent d2415b6 commit d1ee405

5 files changed

Lines changed: 93 additions & 5 deletions

File tree

src/passes/RemoveExports.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
//
2020
// --remove-exports=__*
2121
//
22-
// That will remove all exports with names like "__foo" and "__bar".
22+
// In this case we will remove all exports with names like "__foo" and "__bar".
23+
//
24+
// Exports can also be specified as a comma-separated list, and can be a
25+
// response file.
2326
//
2427

2528
#include "pass.h"
29+
#include "support/file.h"
2630
#include "support/string.h"
2731
#include "wasm.h"
2832

@@ -32,13 +36,21 @@ namespace {
3236

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

42+
param = String::trim(read_possible_response_file(param));
43+
44+
String::Split patterns(param, String::Split::NewLineOr(","));
45+
patterns = handleBracketingOperators(patterns);
46+
3847
std::vector<Name> toRemove;
3948
for (auto& exp : module->exports) {
40-
if (String::wildcardMatch(pattern, exp->name.toString())) {
41-
toRemove.push_back(exp->name);
49+
for (auto& pattern : patterns) {
50+
if (String::wildcardMatch(pattern, exp->name.toString())) {
51+
toRemove.push_back(exp->name);
52+
break;
53+
}
4254
}
4355
}
4456

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foo
2+
bar
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt --remove-exports=@%S/remove-exports-file.txt -all -S -o - | filecheck %s
4+
5+
;; Test a response file as the input to this pass. foo and bar will be removed.
6+
(module
7+
;; CHECK: (type $0 (func))
8+
9+
;; CHECK: (export "keep" (func $keep))
10+
11+
;; CHECK: (func $foo (type $0)
12+
;; CHECK-NEXT: (drop
13+
;; CHECK-NEXT: (i32.const 1)
14+
;; CHECK-NEXT: )
15+
;; CHECK-NEXT: )
16+
(func $foo (export "foo")
17+
(drop (i32.const 1))
18+
)
19+
20+
;; CHECK: (func $bar (type $0)
21+
;; CHECK-NEXT: (drop
22+
;; CHECK-NEXT: (i32.const 2)
23+
;; CHECK-NEXT: )
24+
;; CHECK-NEXT: )
25+
(func $bar (export "bar")
26+
(drop (i32.const 2))
27+
)
28+
29+
;; CHECK: (func $keep (type $0)
30+
;; CHECK-NEXT: (drop
31+
;; CHECK-NEXT: (i32.const 3)
32+
;; CHECK-NEXT: )
33+
;; CHECK-NEXT: )
34+
(func $keep (export "keep")
35+
(drop (i32.const 3))
36+
)
37+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt "--remove-exports=foo<x,y>,bar" -all -S -o - | filecheck %s
4+
5+
;; The two exports mentioned will be removed (note the handling of comma
6+
;; separation, taking into account bracketing). The other will remain.
7+
(module
8+
;; CHECK: (type $0 (func))
9+
10+
;; CHECK: (export "keep" (func $keep))
11+
12+
;; CHECK: (func $"foo<x,y>" (type $0)
13+
;; CHECK-NEXT: (drop
14+
;; CHECK-NEXT: (i32.const 1)
15+
;; CHECK-NEXT: )
16+
;; CHECK-NEXT: )
17+
(func $"foo<x,y>" (export "foo<x,y>")
18+
(drop (i32.const 1))
19+
)
20+
21+
;; CHECK: (func $bar (type $0)
22+
;; CHECK-NEXT: (drop
23+
;; CHECK-NEXT: (i32.const 2)
24+
;; CHECK-NEXT: )
25+
;; CHECK-NEXT: )
26+
(func $bar (export "bar")
27+
(drop (i32.const 2))
28+
)
29+
30+
;; CHECK: (func $keep (type $0)
31+
;; CHECK-NEXT: (drop
32+
;; CHECK-NEXT: (i32.const 3)
33+
;; CHECK-NEXT: )
34+
;; CHECK-NEXT: )
35+
(func $keep (export "keep")
36+
(drop (i32.const 3))
37+
)
38+
)

test/lit/passes/remove-exports.wast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2-
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.
32

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

0 commit comments

Comments
 (0)