-
Notifications
You must be signed in to change notification settings - Fork 855
RemoveExports: Support comma separation and a response file #8674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kripken
wants to merge
3
commits into
WebAssembly:main
Choose a base branch
from
kripken:remove-exports-followup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,12 @@ | |
| // | ||
| // That 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" | ||
|
|
||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| foo | ||
| bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on what we pass and not always two underscores, right? Maybe it's better to clarify.