MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / State

Class State

source/binary.cpp:207–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205
206 // The state used to parse a single SPIR-V binary module.
207 struct State {
208 State(const uint32_t* words_arg, size_t num_words_arg,
209 spv_diagnostic* diagnostic_arg)
210 : words(words_arg),
211 num_words(num_words_arg),
212 diagnostic(diagnostic_arg),
213 word_index(0),
214 instruction_count(0),
215 endian(),
216 requires_endian_conversion(false) {
217 // Temporary storage for parser state within a single instruction.
218 // Most instructions require fewer than 25 words or operands.
219 operands.reserve(25);
220 endian_converted_words.reserve(25);
221 expected_operands.reserve(25);
222 }
223 State() : State(0, 0, nullptr) {}
224 const uint32_t* words; // Words in the binary SPIR-V module.
225 size_t num_words; // Number of words in the module.
226 spv_diagnostic* diagnostic; // Where diagnostics go.
227 size_t word_index; // The current position in words.
228 size_t instruction_count; // The count of processed instructions
229 spv_endianness_t endian; // The endianness of the binary.
230 // Is the SPIR-V binary in a different endianness from the host native
231 // endianness?
232 bool requires_endian_conversion;
233 // Set by parseOperand when LookupOperand fails for an enum operand and
234 // handle_unknown_opcodes_ is set. Signals parseInstruction to discard
235 // the partially-decoded instruction and re-emit it as raw OpUnknown data.
236 // Cleared by parseInstruction immediately before calling emitAsUnknown.
237 bool retry_instruction_as_unknown_ = false;
238
239 // Maps a result ID to its type ID. By convention:
240 // - a result ID that is a type definition maps to itself.
241 // - a result ID without a type maps to 0. (E.g. for OpLabel)
242 std::unordered_map<uint32_t, uint32_t> id_to_type_id;
243 // Maps a type ID to its number type description.
244 std::unordered_map<uint32_t, NumberType> type_id_to_number_type_info;
245 // Maps an ExtInstImport id to the extended instruction type.
246 std::unordered_map<uint32_t, spv_ext_inst_type_t>
247 import_id_to_ext_inst_type;
248
249 // Used by parseOperand
250 std::vector<spv_parsed_operand_t> operands;
251 std::vector<uint32_t> endian_converted_words;
252 spv_operand_pattern_t expected_operands;
253 } _;
254};
255
256spv_result_t Parser::parse(const uint32_t* words, size_t num_words,

Callers 1

parseMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected