• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef LIBSPIRV_TEST_OPT_PASS_UTILS_H_
16 #define LIBSPIRV_TEST_OPT_PASS_UTILS_H_
17 
18 #include <functional>
19 #include <string>
20 #include <vector>
21 
22 namespace spvtools {
23 
24 // In-place substring replacement. Finds the |find_str| in the |process_str|
25 // and replaces the found substring with |replace_str|. Returns true if at
26 // least one replacement is done successfully, returns false otherwise. The
27 // replaced substring won't be processed again, which means: If the
28 // |replace_str| has |find_str| as its substring, that newly replaced part of
29 // |process_str| won't be processed again.
30 bool FindAndReplace(std::string* process_str, const std::string find_str,
31                     const std::string replace_str);
32 
33 // Returns true if the given string contains any debug opcode substring.
34 bool ContainsDebugOpcode(const char* inst);
35 
36 // Returns the concatenated string from a vector of |strings|, with postfixing
37 // each string with the given |delimiter|. if the |skip_dictator| returns true
38 // for an original string, that string will be omitted.
39 std::string SelectiveJoin(const std::vector<const char*>& strings,
40                           const std::function<bool(const char*)>& skip_dictator,
41                           char delimiter = '\n');
42 
43 // Concatenates a vector of strings into one string. Each string is postfixed
44 // with '\n'.
45 std::string JoinAllInsts(const std::vector<const char*>& insts);
46 
47 // Concatenates a vector of strings into one string. Each string is postfixed
48 // with '\n'. If a string contains opcode for debug instruction, that string
49 // will be ignored.
50 std::string JoinNonDebugInsts(const std::vector<const char*>& insts);
51 
52 }  // namespace spvtools
53 
54 #endif  // LIBSPIRV_TEST_OPT_PASS_UTILS_H_
55