| 1 |
// Copyright (c) 2019 Google LLC |
| 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 |
#include "source/fuzz/data_descriptor.h" |
| 16 |
|
| 17 |
#include <algorithm> |
| 18 |
|
| 19 |
namespace spvtools { |
| 20 |
namespace fuzz { |
| 21 |
|
| 22 |
protobufs::DataDescriptor MakeDataDescriptor( |
| 23 |
uint32_t object, const std::vector<uint32_t>& indices) { |
| 24 |
protobufs::DataDescriptor result; |
| 25 |
result.set_object(object); |
| 26 |
for (auto index : indices) { |
| 27 |
result.add_index(index); |
| 28 |
} |
| 29 |
return result; |
| 30 |
} |
| 31 |
|
| 32 |
size_t DataDescriptorHash::operator()( |
| 33 |
const protobufs::DataDescriptor* data_descriptor) const { |
| 34 |
std::u32string hash; |
| 35 |
hash.push_back(data_descriptor->object()); |
| 36 |
for (auto an_index : data_descriptor->index()) { |
| 37 |
hash.push_back(an_index); |
| 38 |
} |
| 39 |
return std::hash<std::u32string>()(hash); |
| 40 |
} |
| 41 |
|
| 42 |
bool DataDescriptorEquals::operator()( |
| 43 |
const protobufs::DataDescriptor* first, |
| 44 |
const protobufs::DataDescriptor* second) const { |
| 45 |
return first->object() == second->object() && |
| 46 |
first->index().size() == second->index().size() && |
| 47 |
std::equal(first->index().begin(), first->index().end(), |
| 48 |
second->index().begin()); |
| 49 |
} |
| 50 |
|
| 51 |
std::ostream& operator<<(std::ostream& out, |
| 52 |
const protobufs::DataDescriptor& data_descriptor) { |
| 53 |
out << data_descriptor.object(); |
| 54 |
out << "["; |
| 55 |
bool first = true; |
| 56 |
for (auto index : data_descriptor.index()) { |
| 57 |
if (first) { |
| 58 |
first = false; |
| 59 |
} else { |
| 60 |
out << ", "; |
| 61 |
} |
| 62 |
out << index; |
| 63 |
} |
| 64 |
out << "]"; |
| 65 |
return out; |
| 66 |
} |
| 67 |
|
| 68 |
} // namespace fuzz |
| 69 |
} // namespace spvtools |