summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge Martin <edb@sigluy.net>2020-09-27 14:12:46 +0200
committerMarge Bot <eric+marge@anholt.net>2020-10-07 13:18:22 +0000
commitfd3209a974f8597170234e29843182a965bcc55a (patch)
tree398fc54e24e1be4ab9f3785ed6ff74914a7078a7
parentee5b46fcfdb4df3d28839499e5945178af9b76f7 (diff)
clover: move tokenize function to algorithm
Reviewed-by: Francisco Jerez <currojerez@riseup.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4974>
-rw-r--r--src/gallium/frontends/clover/llvm/util.hpp44
-rw-r--r--src/gallium/frontends/clover/spirv/invocation.cpp2
-rw-r--r--src/gallium/frontends/clover/util/algorithm.hpp48
3 files changed, 49 insertions, 45 deletions
diff --git a/src/gallium/frontends/clover/llvm/util.hpp b/src/gallium/frontends/clover/llvm/util.hpp
index c3c8890fd07..7cd994bdc86 100644
--- a/src/gallium/frontends/clover/llvm/util.hpp
+++ b/src/gallium/frontends/clover/llvm/util.hpp
@@ -30,7 +30,6 @@
#include <vector>
#include <fstream>
#include <iostream>
-#include <sstream>
namespace clover {
namespace llvm {
@@ -40,49 +39,6 @@ namespace clover {
throw std::forward<E>(e);
}
- inline std::vector<std::string>
- tokenize(const std::string &s) {
- std::vector<std::string> ss;
- std::ostringstream oss;
-
- // OpenCL programs can pass a quoted argument, most frequently the
- // include path. This is useful so that path containing spaces is
- // treated as a single argument instead of being split by the spaces.
- // Additionally, the argument should also be unquoted before being
- // passed to the compiler. We avoid using std::string::replace here to
- // remove quotes, as the single and double quote characters can be a
- // part of the file name.
- bool escape_next = false;
- bool in_quote_double = false;
- bool in_quote_single = false;
-
- for (auto c : s) {
- if (escape_next) {
- oss.put(c);
- escape_next = false;
- } else if (c == '\\') {
- escape_next = true;
- } else if (c == '"' && !in_quote_single) {
- in_quote_double = !in_quote_double;
- } else if (c == '\'' && !in_quote_double) {
- in_quote_single = !in_quote_single;
- } else if (c != ' ' || in_quote_single || in_quote_double) {
- oss.put(c);
- } else if (oss.tellp() > 0) {
- ss.emplace_back(oss.str());
- oss.str("");
- }
- }
-
- if (oss.tellp() > 0)
- ss.emplace_back(oss.str());
-
- if (in_quote_double || in_quote_single)
- throw invalid_build_options_error();
-
- return ss;
- }
-
inline std::string
as_string(const std::vector<char> &v) {
return { v.begin(), v.end() };
diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp
index 33e72296401..a460ce17897 100644
--- a/src/gallium/frontends/clover/spirv/invocation.cpp
+++ b/src/gallium/frontends/clover/spirv/invocation.cpp
@@ -696,7 +696,7 @@ module
clover::spirv::link_program(const std::vector<module> &modules,
const device &dev, const std::string &opts,
std::string &r_log) {
- std::vector<std::string> options = clover::llvm::tokenize(opts);
+ std::vector<std::string> options = tokenize(opts);
bool create_library = false;
diff --git a/src/gallium/frontends/clover/util/algorithm.hpp b/src/gallium/frontends/clover/util/algorithm.hpp
index 0841dd15913..306c045cb2a 100644
--- a/src/gallium/frontends/clover/util/algorithm.hpp
+++ b/src/gallium/frontends/clover/util/algorithm.hpp
@@ -24,6 +24,7 @@
#define CLOVER_UTIL_ALGORITHM_HPP
#include <algorithm>
+#include <sstream>
#include <stdexcept>
#include "util/range.hpp"
@@ -215,6 +216,53 @@ namespace clover {
}
///
+ /// Build a vector of string from a space separated string
+ /// quoted parts content is preserved and unquoted
+ ///
+ inline std::vector<std::string>
+ tokenize(const std::string &s) {
+ std::vector<std::string> ss;
+ std::ostringstream oss;
+
+ // OpenCL programs can pass a quoted argument, most frequently the
+ // include path. This is useful so that path containing spaces is
+ // treated as a single argument instead of being split by the spaces.
+ // Additionally, the argument should also be unquoted before being
+ // passed to the compiler. We avoid using std::string::replace here to
+ // remove quotes, as the single and double quote characters can be a
+ // part of the file name.
+ bool escape_next = false;
+ bool in_quote_double = false;
+ bool in_quote_single = false;
+
+ for (auto c : s) {
+ if (escape_next) {
+ oss.put(c);
+ escape_next = false;
+ } else if (c == '\\') {
+ escape_next = true;
+ } else if (c == '"' && !in_quote_single) {
+ in_quote_double = !in_quote_double;
+ } else if (c == '\'' && !in_quote_double) {
+ in_quote_single = !in_quote_single;
+ } else if (c != ' ' || in_quote_single || in_quote_double) {
+ oss.put(c);
+ } else if (oss.tellp() > 0) {
+ ss.emplace_back(oss.str());
+ oss.str("");
+ }
+ }
+
+ if (oss.tellp() > 0)
+ ss.emplace_back(oss.str());
+
+ if (in_quote_double || in_quote_single)
+ throw invalid_build_options_error();
+
+ return ss;
+ }
+
+ ///
/// Build a \a sep separated string from a vector of T
///
template<typename T>