Dejan Mircevski | b6fe02f | 2016-01-07 13:44:22 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 2 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame^] | 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 |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 6 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame^] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 8 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame^] | 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. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 14 | |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 15 | #ifndef LIBSPIRV_TEXT_HANDLER_H_ |
| 16 | #define LIBSPIRV_TEXT_HANDLER_H_ |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 17 | |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 18 | #include <iomanip> |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 19 | #include <sstream> |
| 20 | #include <type_traits> |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 21 | #include <unordered_map> |
| 22 | |
| 23 | #include "diagnostic.h" |
David Neto | b5dc8fc | 2015-10-06 16:22:00 -0400 | [diff] [blame] | 24 | #include "instruction.h" |
David Neto | 5a70335 | 2016-02-17 14:44:00 -0500 | [diff] [blame] | 25 | #include "spirv-tools/libspirv.h" |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 26 | #include "text.h" |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 27 | |
| 28 | namespace libspirv { |
| 29 | // Structures |
| 30 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 31 | // This is a lattice for tracking types. |
| 32 | enum class IdTypeClass { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 33 | kBottom = 0, // We have no information yet. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 34 | kScalarIntegerType, |
| 35 | kScalarFloatType, |
| 36 | kOtherType |
| 37 | }; |
| 38 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 39 | // Contains ID type information that needs to be tracked across all Ids. |
| 40 | // Bitwidth is only valid when type_class is kScalarIntegerType or |
| 41 | // kScalarFloatType. |
| 42 | struct IdType { |
| 43 | uint32_t bitwidth; // Safe to assume that we will not have > 2^32 bits. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 44 | bool isSigned; // This is only significant if type_class is integral. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 45 | IdTypeClass type_class; |
| 46 | }; |
| 47 | |
Andrew Woloszyn | 157e41b | 2015-10-16 15:11:00 -0400 | [diff] [blame] | 48 | // Default equality operator for IdType. Tests if all members are the same. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 49 | inline bool operator==(const IdType& first, const IdType& second) { |
Andrew Woloszyn | 157e41b | 2015-10-16 15:11:00 -0400 | [diff] [blame] | 50 | return (first.bitwidth == second.bitwidth) && |
| 51 | (first.isSigned == second.isSigned) && |
| 52 | (first.type_class == second.type_class); |
| 53 | } |
| 54 | |
| 55 | // Tests whether any member of the IdTypes do not match. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 56 | inline bool operator!=(const IdType& first, const IdType& second) { |
Andrew Woloszyn | 157e41b | 2015-10-16 15:11:00 -0400 | [diff] [blame] | 57 | return !(first == second); |
| 58 | } |
| 59 | |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 60 | // A value representing an unknown type. |
| 61 | extern const IdType kUnknownType; |
| 62 | |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 63 | // Returns true if the type is a scalar integer type. |
| 64 | inline bool isScalarIntegral(const IdType& type) { |
| 65 | return type.type_class == IdTypeClass::kScalarIntegerType; |
| 66 | } |
| 67 | |
| 68 | // Returns true if the type is a scalar floating point type. |
| 69 | inline bool isScalarFloating(const IdType& type) { |
| 70 | return type.type_class == IdTypeClass::kScalarFloatType; |
| 71 | } |
| 72 | |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 73 | // Returns the number of bits in the type. |
| 74 | // This is only valid for bottom, scalar integer, and scalar floating |
| 75 | // classes. For bottom, assume 32 bits. |
| 76 | inline int assumedBitWidth(const IdType& type) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 77 | switch (type.type_class) { |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 78 | case IdTypeClass::kBottom: |
| 79 | return 32; |
| 80 | case IdTypeClass::kScalarIntegerType: |
| 81 | case IdTypeClass::kScalarFloatType: |
| 82 | return type.bitwidth; |
| 83 | default: |
| 84 | break; |
| 85 | } |
| 86 | // We don't care about this case. |
| 87 | return 0; |
| 88 | } |
| 89 | |
David Neto | 9e545d7 | 2015-11-06 18:08:49 -0500 | [diff] [blame] | 90 | // A templated class with a static member function Clamp, where Clamp |
| 91 | // sets a referenced value of type T to 0 if T is an unsigned |
| 92 | // integer type, and returns true if it modified the referenced |
| 93 | // value. |
| 94 | template <typename T, typename = void> |
| 95 | class ClampToZeroIfUnsignedType { |
| 96 | public: |
| 97 | // The default specialization does not clamp the value. |
| 98 | static bool Clamp(T*) { return false; } |
| 99 | }; |
| 100 | |
| 101 | // The specialization of ClampToZeroIfUnsignedType for unsigned integer |
| 102 | // types. |
| 103 | template <typename T> |
| 104 | class ClampToZeroIfUnsignedType< |
| 105 | T, typename std::enable_if<std::is_unsigned<T>::value>::type> { |
| 106 | public: |
| 107 | static bool Clamp(T* value_pointer) { |
| 108 | if (*value_pointer) { |
| 109 | *value_pointer = 0; |
| 110 | return true; |
| 111 | } |
| 112 | return false; |
| 113 | } |
| 114 | }; |
| 115 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 116 | // Encapsulates the data used during the assembly of a SPIR-V module. |
| 117 | class AssemblyContext { |
| 118 | public: |
David Neto | ae7d707 | 2016-01-06 14:43:55 -0500 | [diff] [blame] | 119 | AssemblyContext(spv_text text, spv_diagnostic* diagnostic_arg) |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 120 | : current_position_({}), |
David Neto | ae7d707 | 2016-01-06 14:43:55 -0500 | [diff] [blame] | 121 | pDiagnostic_(diagnostic_arg), |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 122 | text_(text), |
| 123 | bound_(1) {} |
| 124 | |
| 125 | // Assigns a new integer value to the given text ID, or returns the previously |
| 126 | // assigned integer value if the ID has been seen before. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 127 | uint32_t spvNamedIdAssignOrGet(const char* textValue); |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 128 | |
| 129 | // Returns the largest largest numeric ID that has been assigned. |
| 130 | uint32_t getBound() const; |
| 131 | |
| 132 | // Advances position to point to the next word in the input stream. |
| 133 | // Returns SPV_SUCCESS on success. |
| 134 | spv_result_t advance(); |
| 135 | |
Lei Zhang | 6032b98 | 2016-03-15 16:52:40 -0400 | [diff] [blame] | 136 | // Sets word to the next word in the input text. Fills next_position with |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 137 | // the next location past the end of the word. |
Lei Zhang | 6032b98 | 2016-03-15 16:52:40 -0400 | [diff] [blame] | 138 | spv_result_t getWord(std::string* word, spv_position next_position); |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 139 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 140 | // Returns true if the next word in the input is the start of a new Opcode. |
| 141 | bool startsWithOp(); |
| 142 | |
| 143 | // Returns true if the next word in the input is the start of a new |
| 144 | // instruction. |
| 145 | bool isStartOfNewInst(); |
| 146 | |
| 147 | // Returns a diagnostic object initialized with current position in the input |
David Neto | ac508b0 | 2015-10-09 15:48:09 -0400 | [diff] [blame] | 148 | // stream, and for the given error code. Any data written to this object will |
| 149 | // show up in pDiagnsotic on destruction. |
| 150 | DiagnosticStream diagnostic(spv_result_t error) { |
David Neto | bae8851 | 2015-10-28 13:16:56 -0400 | [diff] [blame] | 151 | return DiagnosticStream(current_position_, pDiagnostic_, error); |
David Neto | ac508b0 | 2015-10-09 15:48:09 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | // Returns a diagnostic object with the default assembly error code. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 155 | DiagnosticStream diagnostic() { |
David Neto | ac508b0 | 2015-10-09 15:48:09 -0400 | [diff] [blame] | 156 | // The default failure for assembly is invalid text. |
| 157 | return diagnostic(SPV_ERROR_INVALID_TEXT); |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Lei Zhang | acf7287 | 2015-11-13 11:00:10 -0500 | [diff] [blame] | 160 | // Returns then next character in the input stream. |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 161 | char peek() const; |
| 162 | |
| 163 | // Returns true if there is more text in the input stream. |
| 164 | bool hasText() const; |
| 165 | |
| 166 | // Seeks the input stream forward by 'size' characters. |
| 167 | void seekForward(uint32_t size); |
| 168 | |
| 169 | // Sets the current position in the input stream to the given position. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 170 | void setPosition(const spv_position_t& newPosition) { |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 171 | current_position_ = newPosition; |
| 172 | } |
| 173 | |
| 174 | // Returns the current position in the input stream. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 175 | const spv_position_t& position() const { return current_position_; } |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 176 | |
| 177 | // Appends the given 32-bit value to the given instruction. |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 178 | // Returns SPV_SUCCESS if the value could be correctly inserted in the |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 179 | // instruction. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 180 | spv_result_t binaryEncodeU32(const uint32_t value, spv_instruction_t* pInst); |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 181 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 182 | // Appends the given string to the given instruction. |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 183 | // Returns SPV_SUCCESS if the value could be correctly inserted in the |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 184 | // instruction. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 185 | spv_result_t binaryEncodeString(const char* value, spv_instruction_t* pInst); |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 186 | |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 187 | // Appends the given numeric literal to the given instruction. |
| 188 | // Validates and respects the bitwidth supplied in the IdType argument. |
| 189 | // If the type is of class kBottom the value will be encoded as a |
| 190 | // 32-bit integer. |
| 191 | // Returns SPV_SUCCESS if the value could be correctly added to the |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 192 | // instruction. Returns the given error code on failure, and emits |
Lei Zhang | acf7287 | 2015-11-13 11:00:10 -0500 | [diff] [blame] | 193 | // a diagnostic if that error code is not SPV_FAILED_MATCH. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 194 | spv_result_t binaryEncodeNumericLiteral(const char* numeric_literal, |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 195 | spv_result_t error_code, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 196 | const IdType& type, |
| 197 | spv_instruction_t* pInst); |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 198 | |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 199 | // Returns the IdType associated with this type-generating value. |
| 200 | // If the type has not been previously recorded with recordTypeDefinition, |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 201 | // kUnknownType will be returned. |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 202 | IdType getTypeOfTypeGeneratingValue(uint32_t value) const; |
| 203 | |
| 204 | // Returns the IdType that represents the return value of this Value |
| 205 | // generating instruction. |
| 206 | // If the value has not been recorded with recordTypeIdForValue, or the type |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 207 | // could not be determined kUnknownType will be returned. |
Andrew Woloszyn | 537e776 | 2015-09-29 11:28:34 -0400 | [diff] [blame] | 208 | IdType getTypeOfValueInstruction(uint32_t value) const; |
| 209 | |
| 210 | // Tracks the type-defining instruction. The result of the tracking can |
| 211 | // later be queried using getValueType. |
| 212 | // pInst is expected to be completely filled in by the time this instruction |
| 213 | // is called. |
| 214 | // Returns SPV_SUCCESS on success, or SPV_ERROR_INVALID_VALUE on error. |
| 215 | spv_result_t recordTypeDefinition(const spv_instruction_t* pInst); |
| 216 | |
| 217 | // Tracks the relationship between the value and its type. |
| 218 | spv_result_t recordTypeIdForValue(uint32_t value, uint32_t type); |
| 219 | |
David Neto | 2ae4a68 | 2015-11-09 18:55:42 -0500 | [diff] [blame] | 220 | // Records the given Id as being the import of the given extended instruction |
| 221 | // type. |
| 222 | spv_result_t recordIdAsExtInstImport(uint32_t id, spv_ext_inst_type_t type); |
| 223 | |
| 224 | // Returns the extended instruction type corresponding to the import with |
| 225 | // the given Id, if it exists. Returns SPV_EXT_INST_TYPE_NONE if the |
| 226 | // id is not the id for an extended instruction type. |
| 227 | spv_ext_inst_type_t getExtInstTypeForId(uint32_t id) const; |
| 228 | |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 229 | // Parses a numeric value of a given type from the given text. The number |
| 230 | // should take up the entire string, and should be within bounds for the |
| 231 | // target type. On success, returns SPV_SUCCESS and populates the object |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 232 | // referenced by value_pointer. On failure, returns the given error code, |
| 233 | // and emits a diagnostic if that error code is not SPV_FAILED_MATCH. |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 234 | template <typename T> |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 235 | spv_result_t parseNumber(const char* text, spv_result_t error_code, |
| 236 | T* value_pointer, |
| 237 | const char* error_message_fragment) { |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 238 | // C++11 doesn't define std::istringstream(int8_t&), so calling this method |
| 239 | // with a single-byte type leads to implementation-defined behaviour. |
| 240 | // Similarly for uint8_t. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 241 | static_assert(sizeof(T) > 1, |
| 242 | "Don't use a single-byte type this parse method"); |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 243 | |
| 244 | std::istringstream text_stream(text); |
| 245 | // Allow both decimal and hex input for integers. |
| 246 | // It also allows octal input, but we don't care about that case. |
| 247 | text_stream >> std::setbase(0); |
| 248 | text_stream >> *value_pointer; |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 249 | |
| 250 | // We should have read something. |
Lei Zhang | 712bed0 | 2016-02-25 16:11:16 -0500 | [diff] [blame] | 251 | bool ok = (text[0] != 0) && !text_stream.bad(); |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 252 | // It should have been all the text. |
| 253 | ok = ok && text_stream.eof(); |
| 254 | // It should have been in range. |
| 255 | ok = ok && !text_stream.fail(); |
David Neto | 9e545d7 | 2015-11-06 18:08:49 -0500 | [diff] [blame] | 256 | |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 257 | // Work around a bug in the GNU C++11 library. It will happily parse |
| 258 | // "-1" for uint16_t as 65535. |
David Neto | 9e545d7 | 2015-11-06 18:08:49 -0500 | [diff] [blame] | 259 | if (ok && text[0] == '-') |
| 260 | ok = !ClampToZeroIfUnsignedType<T>::Clamp(value_pointer); |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 261 | |
| 262 | if (ok) return SPV_SUCCESS; |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 263 | return diagnostic(error_code) << error_message_fragment << text; |
David Neto | 6274120 | 2015-10-13 15:51:12 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 266 | private: |
Andrew Woloszyn | 4ddb431 | 2016-02-17 13:00:23 -0500 | [diff] [blame] | 267 | |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 268 | // Appends the given floating point literal to the given instruction. |
| 269 | // Returns SPV_SUCCESS if the value was correctly parsed. Otherwise |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 270 | // returns the given error code, and emits a diagnostic if that error |
| 271 | // code is not SPV_FAILED_MATCH. |
| 272 | // Only 32 and 64 bit floating point numbers are supported. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 273 | spv_result_t binaryEncodeFloatingPointLiteral(const char* numeric_literal, |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 274 | spv_result_t error_code, |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 275 | const IdType& type, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 276 | spv_instruction_t* pInst); |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 277 | |
| 278 | // Appends the given integer literal to the given instruction. |
| 279 | // Returns SPV_SUCCESS if the value was correctly parsed. Otherwise |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 280 | // returns the given error code, and emits a diagnostic if that error |
| 281 | // code is not SPV_FAILED_MATCH. |
| 282 | // Integers up to 64 bits are supported. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 283 | spv_result_t binaryEncodeIntegerLiteral(const char* numeric_literal, |
David Neto | 51013d1 | 2015-10-14 11:31:51 -0400 | [diff] [blame] | 284 | spv_result_t error_code, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 285 | const IdType& type, |
| 286 | spv_instruction_t* pInst); |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 287 | |
David Neto | 78e677b | 2015-10-05 13:28:46 -0400 | [diff] [blame] | 288 | // Writes the given 64-bit literal value into the instruction. |
| 289 | // return SPV_SUCCESS if the value could be written in the instruction. |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 290 | spv_result_t binaryEncodeU64(const uint64_t value, spv_instruction_t* pInst); |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 291 | // Maps ID names to their corresponding numerical ids. |
| 292 | using spv_named_id_table = std::unordered_map<std::string, uint32_t>; |
| 293 | // Maps type-defining IDs to their IdType. |
| 294 | using spv_id_to_type_map = std::unordered_map<uint32_t, IdType>; |
| 295 | // Maps Ids to the id of their type. |
| 296 | using spv_id_to_type_id = std::unordered_map<uint32_t, uint32_t>; |
| 297 | |
| 298 | spv_named_id_table named_ids_; |
| 299 | spv_id_to_type_map types_; |
| 300 | spv_id_to_type_id value_types_; |
David Neto | 2ae4a68 | 2015-11-09 18:55:42 -0500 | [diff] [blame] | 301 | // Maps an extended instruction import Id to the extended instruction type. |
| 302 | std::unordered_map<uint32_t, spv_ext_inst_type_t> import_id_to_ext_inst_type_; |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 303 | spv_position_t current_position_; |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 304 | spv_diagnostic* pDiagnostic_; |
Andrew Woloszyn | 71fc055 | 2015-09-24 10:26:51 -0400 | [diff] [blame] | 305 | spv_text text_; |
| 306 | uint32_t bound_; |
| 307 | }; |
| 308 | } |
David Neto | 9f79d78 | 2015-10-27 16:27:05 -0400 | [diff] [blame] | 309 | #endif // _LIBSPIRV_TEXT_HANDLER_H_ |