diff options
-rw-r--r-- | src/passes/Asyncify.cpp | 11 | ||||
-rw-r--r-- | src/support/string.h | 39 | ||||
-rw-r--r-- | test/lit/passes/asyncify-foo,bar-nl.txt | 2 | ||||
-rw-r--r-- | test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast | 1 | ||||
-rw-r--r-- | test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast | 1 |
5 files changed, 47 insertions, 7 deletions
diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index 2412a754a..b30af085e 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -1626,7 +1626,8 @@ struct Asyncify : public Pass { options.getArgumentOrDefault("asyncify-ignore-imports", ""); bool allImportsCanChangeState = stateChangingImports == "" && ignoreImports == ""; - String::Split listedImports(stateChangingImports, ","); + String::Split listedImports(stateChangingImports, + String::Split::NewLineOr(",")); // canIndirectChangeState is the default. asyncify-ignore-indirect sets it // to false. auto canIndirectChangeState = @@ -1638,11 +1639,12 @@ struct Asyncify : public Pass { removeListInput = options.getArgumentOrDefault("asyncify-blacklist", ""); } String::Split removeList( - String::trim(read_possible_response_file(removeListInput)), ","); + String::trim(read_possible_response_file(removeListInput)), + String::Split::NewLineOr(",")); String::Split addList( String::trim(read_possible_response_file( options.getArgumentOrDefault("asyncify-addlist", ""))), - ","); + String::Split::NewLineOr(",")); std::string onlyListInput = options.getArgumentOrDefault("asyncify-onlylist", ""); if (onlyListInput.empty()) { @@ -1650,7 +1652,8 @@ struct Asyncify : public Pass { onlyListInput = options.getArgumentOrDefault("asyncify-whitelist", ""); } String::Split onlyList( - String::trim(read_possible_response_file(onlyListInput)), ","); + String::trim(read_possible_response_file(onlyListInput)), + String::Split::NewLineOr(",")); auto asserts = options.hasArgument("asyncify-asserts"); auto verbose = options.hasArgument("asyncify-verbose"); auto relocatable = options.hasArgument("asyncify-relocatable"); diff --git a/src/support/string.h b/src/support/string.h index a73121f6b..751efdac5 100644 --- a/src/support/string.h +++ b/src/support/string.h @@ -31,10 +31,14 @@ namespace wasm::String { // Creates a vector of the split parts of a string, by a delimiter. class Split : public std::vector<std::string> { -public: - Split() = default; +private: + // If we split on newlines then we do not need to handle bracketing at all. + // Otherwise, splitting on say "," does require us to understanding the + // scoping of brackets, e.g., "foo(x, y),bar" should be split as "foo(x, y)", + // "bar". + bool needToHandleBracketingOperations = true; - Split(const std::string& input, const std::string& delim) { + void split(const std::string& input, const std::string& delim) { size_t lastEnd = 0; while (lastEnd < input.size()) { auto nextDelim = input.find(delim, lastEnd); @@ -44,6 +48,31 @@ public: (*this).push_back(input.substr(lastEnd, nextDelim - lastEnd)); lastEnd = nextDelim + delim.size(); } + needToHandleBracketingOperations = delim != "\n"; + } + friend String::Split handleBracketingOperators(String::Split split); + +public: + // This can be used when we want to split on newlines if there are any, and if + // there are not, then using the given delimiter. + struct NewLineOr { + const std::string delim; + explicit NewLineOr(const std::string& delim) : delim(delim) {} + }; + + Split() = default; + + Split(const std::string& input, const NewLineOr& newLineOrDelim) { + auto first = input.find("\n", 0); + if (first != std::string::npos && first != input.length() - 1) { + split(input, "\n"); + } else { + split(input, newLineOrDelim.delim); + } + } + + Split(const std::string& input, const std::string& delim) { + split(input, delim); } }; @@ -53,6 +82,10 @@ public: // must be kept together because of the "(". Likewise, "{", "<", "[" are // handled. inline String::Split handleBracketingOperators(String::Split split) { + if (!split.needToHandleBracketingOperations) { + return split; + } + String::Split ret; std::string last; int nesting = 0; diff --git a/test/lit/passes/asyncify-foo,bar-nl.txt b/test/lit/passes/asyncify-foo,bar-nl.txt new file mode 100644 index 000000000..a907ec3f4 --- /dev/null +++ b/test/lit/passes/asyncify-foo,bar-nl.txt @@ -0,0 +1,2 @@ +foo +bar
\ No newline at end of file diff --git a/test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast b/test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast index c2e81126c..dcc864713 100644 --- a/test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast +++ b/test/lit/passes/asyncify_pass-arg=asyncify-blacklist@foo,bar.wast @@ -2,6 +2,7 @@ ;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. ;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-blacklist@foo,bar -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-blacklist@@%S/asyncify-foo,bar-nl.txt -S -o - | filecheck %s (module (memory 1 2) diff --git a/test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast b/test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast index 370ce4f6d..ba5c59cd1 100644 --- a/test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast +++ b/test/lit/passes/asyncify_pass-arg=asyncify-onlylist@foo,bar.wast @@ -2,6 +2,7 @@ ;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. ;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-onlylist@foo,bar -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --asyncify --pass-arg=asyncify-onlylist@@%S/asyncify-foo,bar-nl.txt -S -o - | filecheck %s (module (memory 1 2) |