2016-06-28 18:58:17 +00:00
|
|
|
// Copyright (c) 2016 Google Inc.
|
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2016-06-28 18:58:17 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-28 18:58:17 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-06-28 18:58:17 +00:00
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#ifndef TEST_OPT_PASS_UTILS_H_
|
|
|
|
#define TEST_OPT_PASS_UTILS_H_
|
2016-06-28 18:58:17 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <algorithm>
|
2016-06-28 18:58:17 +00:00
|
|
|
#include <functional>
|
2018-03-30 14:00:32 +00:00
|
|
|
#include <iterator>
|
2016-06-28 18:58:17 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-10-12 00:20:48 +00:00
|
|
|
#include "gtest/gtest.h"
|
2018-10-10 19:18:15 +00:00
|
|
|
#include "include/spirv-tools/libspirv.h"
|
|
|
|
#include "include/spirv-tools/libspirv.hpp"
|
|
|
|
|
2016-06-28 18:58:17 +00:00
|
|
|
namespace spvtools {
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace opt {
|
2016-06-28 18:58:17 +00:00
|
|
|
|
2018-10-10 19:18:15 +00:00
|
|
|
struct Message {
|
|
|
|
spv_message_level_t level;
|
|
|
|
const char* source_file;
|
|
|
|
uint32_t line_number;
|
|
|
|
uint32_t column_number;
|
|
|
|
const char* message;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return a message consumer that can be used to check that the message produced
|
|
|
|
// are the messages in |expexted_messages|, and in the same order.
|
|
|
|
MessageConsumer GetTestMessageConsumer(std::vector<Message>& expected_messages);
|
|
|
|
|
2016-07-27 21:22:45 +00:00
|
|
|
// In-place substring replacement. Finds the |find_str| in the |process_str|
|
|
|
|
// and replaces the found substring with |replace_str|. Returns true if at
|
|
|
|
// least one replacement is done successfully, returns false otherwise. The
|
|
|
|
// replaced substring won't be processed again, which means: If the
|
|
|
|
// |replace_str| has |find_str| as its substring, that newly replaced part of
|
|
|
|
// |process_str| won't be processed again.
|
|
|
|
bool FindAndReplace(std::string* process_str, const std::string find_str,
|
|
|
|
const std::string replace_str);
|
|
|
|
|
|
|
|
// Returns true if the given string contains any debug opcode substring.
|
|
|
|
bool ContainsDebugOpcode(const char* inst);
|
|
|
|
|
2016-06-28 18:58:17 +00:00
|
|
|
// Returns the concatenated string from a vector of |strings|, with postfixing
|
|
|
|
// each string with the given |delimiter|. if the |skip_dictator| returns true
|
|
|
|
// for an original string, that string will be omitted.
|
|
|
|
std::string SelectiveJoin(const std::vector<const char*>& strings,
|
|
|
|
const std::function<bool(const char*)>& skip_dictator,
|
|
|
|
char delimiter = '\n');
|
|
|
|
|
|
|
|
// Concatenates a vector of strings into one string. Each string is postfixed
|
|
|
|
// with '\n'.
|
|
|
|
std::string JoinAllInsts(const std::vector<const char*>& insts);
|
|
|
|
|
|
|
|
// Concatenates a vector of strings into one string. Each string is postfixed
|
|
|
|
// with '\n'. If a string contains opcode for debug instruction, that string
|
|
|
|
// will be ignored.
|
|
|
|
std::string JoinNonDebugInsts(const std::vector<const char*>& insts);
|
|
|
|
|
2017-09-08 16:08:03 +00:00
|
|
|
// Returns a vector that contains the contents of |a| followed by the contents
|
|
|
|
// of |b|.
|
|
|
|
template <typename T>
|
|
|
|
std::vector<T> Concat(const std::vector<T>& a, const std::vector<T>& b) {
|
|
|
|
std::vector<T> ret;
|
|
|
|
std::copy(a.begin(), a.end(), back_inserter(ret));
|
|
|
|
std::copy(b.begin(), b.end(), back_inserter(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace opt
|
2016-06-28 18:58:17 +00:00
|
|
|
} // namespace spvtools
|
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#endif // TEST_OPT_PASS_UTILS_H_
|