| 49 | // to an existing vector. |
| 50 | template <class VectorType = std::vector<uint32_t>> |
| 51 | inline void AppendToVector(const std::string& input, VectorType* result) { |
| 52 | static_assert(std::is_same<uint32_t, typename VectorType::value_type>::value); |
| 53 | uint32_t word = 0; |
| 54 | size_t num_bytes = input.size(); |
| 55 | // SPIR-V strings are null-terminated. The byte_index == num_bytes |
| 56 | // case is used to push the terminating null byte. |
| 57 | for (size_t byte_index = 0; byte_index <= num_bytes; byte_index++) { |
| 58 | const auto new_byte = |
| 59 | (byte_index < num_bytes ? uint8_t(input[byte_index]) : uint8_t(0)); |
| 60 | word |= (new_byte << (8 * (byte_index % sizeof(uint32_t)))); |
| 61 | if (3 == (byte_index % sizeof(uint32_t))) { |
| 62 | result->push_back(word); |
| 63 | word = 0; |
| 64 | } |
| 65 | } |
| 66 | // Emit a trailing partial word. |
| 67 | if ((num_bytes + 1) % sizeof(uint32_t)) { |
| 68 | result->push_back(word); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Encodes a string as a sequence of words, using the SPIR-V encoding. |
| 73 | template <class VectorType = std::vector<uint32_t>> |
no test coverage detected