Skip to content

Commit 40e0744

Browse files
committed
Fix #6047, #5271: Support one-line-one-function file format for asyncify lists
1 parent 2c0fb8c commit 40e0744

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

src/passes/Asyncify.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,8 @@ struct Asyncify : public Pass {
15331533
options.getArgumentOrDefault("asyncify-ignore-imports", "");
15341534
bool allImportsCanChangeState =
15351535
stateChangingImports == "" && ignoreImports == "";
1536-
String::Split listedImports(stateChangingImports, ",");
1536+
String::Split listedImports(stateChangingImports,
1537+
String::Split::NewLineOr(","));
15371538
// canIndirectChangeState is the default. asyncify-ignore-indirect sets it
15381539
// to false.
15391540
auto canIndirectChangeState =
@@ -1545,19 +1546,21 @@ struct Asyncify : public Pass {
15451546
removeListInput = options.getArgumentOrDefault("asyncify-blacklist", "");
15461547
}
15471548
String::Split removeList(
1548-
String::trim(read_possible_response_file(removeListInput)), ",");
1549+
String::trim(read_possible_response_file(removeListInput)),
1550+
String::Split::NewLineOr(","));
15491551
String::Split addList(
15501552
String::trim(read_possible_response_file(
15511553
options.getArgumentOrDefault("asyncify-addlist", ""))),
1552-
",");
1554+
String::Split::NewLineOr(","));
15531555
std::string onlyListInput =
15541556
options.getArgumentOrDefault("asyncify-onlylist", "");
15551557
if (onlyListInput.empty()) {
15561558
// Support old name for now to avoid immediate breakage TODO remove
15571559
onlyListInput = options.getArgumentOrDefault("asyncify-whitelist", "");
15581560
}
15591561
String::Split onlyList(
1560-
String::trim(read_possible_response_file(onlyListInput)), ",");
1562+
String::trim(read_possible_response_file(onlyListInput)),
1563+
String::Split::NewLineOr(","));
15611564
auto asserts = options.hasArgument("asyncify-asserts");
15621565
auto verbose = options.hasArgument("asyncify-verbose");
15631566
auto relocatable = options.hasArgument("asyncify-relocatable");

src/support/string.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ namespace wasm::String {
3131

3232
// Creates a vector of the split parts of a string, by a delimiter.
3333
class Split : public std::vector<std::string> {
34-
public:
35-
Split() = default;
36-
37-
Split(const std::string& input, const std::string& delim) {
34+
private:
35+
bool needToHandleBracketingOperations = true;
36+
void split(const std::string& input, const std::string& delim) {
3837
size_t lastEnd = 0;
3938
while (lastEnd < input.size()) {
4039
auto nextDelim = input.find(delim, lastEnd);
@@ -44,6 +43,29 @@ class Split : public std::vector<std::string> {
4443
(*this).push_back(input.substr(lastEnd, nextDelim - lastEnd));
4544
lastEnd = nextDelim + delim.size();
4645
}
46+
needToHandleBracketingOperations = delim != "\n";
47+
}
48+
friend String::Split handleBracketingOperators(String::Split split);
49+
50+
public:
51+
struct NewLineOr {
52+
const std::string delim;
53+
explicit NewLineOr(const std::string& delim) : delim(delim) {}
54+
};
55+
56+
Split() = default;
57+
58+
Split(const std::string& input, const NewLineOr& newLineOrDelim) {
59+
auto first = input.find("\n", 0);
60+
if (first != std::string::npos && first != input.length() - 1) {
61+
split(input, "\n");
62+
} else {
63+
split(input, newLineOrDelim.delim);
64+
}
65+
}
66+
67+
Split(const std::string& input, const std::string& delim) {
68+
split(input, delim);
4769
}
4870
};
4971

@@ -53,6 +75,10 @@ class Split : public std::vector<std::string> {
5375
// must be kept together because of the "(". Likewise, "{", "<", "[" are
5476
// handled.
5577
inline String::Split handleBracketingOperators(String::Split split) {
78+
if (!split.needToHandleBracketingOperations) {
79+
return split;
80+
}
81+
5682
String::Split ret;
5783
std::string last;
5884
int nesting = 0;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foo
2+
bar

test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.
33

44
;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-blacklist@foo,bar -S -o - | filecheck %s
5+
;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-blacklist@@%S/asyncify-foo,bar-nl.txt -S -o - | filecheck %s
56

67
(module
78
(memory 1 2)

test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.
33

44
;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-onlylist@foo,bar -S -o - | filecheck %s
5+
;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-onlylist@@%S/asyncify-foo,bar-nl.txt -S -o - | filecheck %s
56

67
(module
78
(memory 1 2)

0 commit comments

Comments
 (0)