• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015-2020 The Khronos Group Inc.
2 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
3 // reserved.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
18 #define INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #else
23 #include <stdbool.h>
24 #endif
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #if defined(SPIRV_TOOLS_SHAREDLIB)
30 #if defined(_WIN32)
31 #if defined(SPIRV_TOOLS_IMPLEMENTATION)
32 #define SPIRV_TOOLS_EXPORT __declspec(dllexport)
33 #else
34 #define SPIRV_TOOLS_EXPORT __declspec(dllimport)
35 #endif
36 #else
37 #if defined(SPIRV_TOOLS_IMPLEMENTATION)
38 #define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
39 #else
40 #define SPIRV_TOOLS_EXPORT
41 #endif
42 #endif
43 #else
44 #define SPIRV_TOOLS_EXPORT
45 #endif
46 
47 // Helpers
48 
49 #define SPV_BIT(shift) (1 << (shift))
50 
51 #define SPV_FORCE_16_BIT_ENUM(name) SPV_FORCE_16BIT_##name = 0x7fff
52 #define SPV_FORCE_32_BIT_ENUM(name) SPV_FORCE_32BIT_##name = 0x7fffffff
53 
54 // Enumerations
55 
56 typedef enum spv_result_t {
57   SPV_SUCCESS = 0,
58   SPV_UNSUPPORTED = 1,
59   SPV_END_OF_STREAM = 2,
60   SPV_WARNING = 3,
61   SPV_FAILED_MATCH = 4,
62   SPV_REQUESTED_TERMINATION = 5,  // Success, but signals early termination.
63   SPV_ERROR_INTERNAL = -1,
64   SPV_ERROR_OUT_OF_MEMORY = -2,
65   SPV_ERROR_INVALID_POINTER = -3,
66   SPV_ERROR_INVALID_BINARY = -4,
67   SPV_ERROR_INVALID_TEXT = -5,
68   SPV_ERROR_INVALID_TABLE = -6,
69   SPV_ERROR_INVALID_VALUE = -7,
70   SPV_ERROR_INVALID_DIAGNOSTIC = -8,
71   SPV_ERROR_INVALID_LOOKUP = -9,
72   SPV_ERROR_INVALID_ID = -10,
73   SPV_ERROR_INVALID_CFG = -11,
74   SPV_ERROR_INVALID_LAYOUT = -12,
75   SPV_ERROR_INVALID_CAPABILITY = -13,
76   SPV_ERROR_INVALID_DATA = -14,  // Indicates data rules validation failure.
77   SPV_ERROR_MISSING_EXTENSION = -15,
78   SPV_ERROR_WRONG_VERSION = -16,  // Indicates wrong SPIR-V version
79   SPV_FORCE_32_BIT_ENUM(spv_result_t)
80 } spv_result_t;
81 
82 // Severity levels of messages communicated to the consumer.
83 typedef enum spv_message_level_t {
84   SPV_MSG_FATAL,           // Unrecoverable error due to environment.
85                            // Will exit the program immediately. E.g.,
86                            // out of memory.
87   SPV_MSG_INTERNAL_ERROR,  // Unrecoverable error due to SPIRV-Tools
88                            // internals.
89                            // Will exit the program immediately. E.g.,
90                            // unimplemented feature.
91   SPV_MSG_ERROR,           // Normal error due to user input.
92   SPV_MSG_WARNING,         // Warning information.
93   SPV_MSG_INFO,            // General information.
94   SPV_MSG_DEBUG,           // Debug information.
95 } spv_message_level_t;
96 
97 typedef enum spv_endianness_t {
98   SPV_ENDIANNESS_LITTLE,
99   SPV_ENDIANNESS_BIG,
100   SPV_FORCE_32_BIT_ENUM(spv_endianness_t)
101 } spv_endianness_t;
102 
103 // The kinds of operands that an instruction may have.
104 //
105 // Some operand types are "concrete".  The binary parser uses a concrete
106 // operand type to describe an operand of a parsed instruction.
107 //
108 // The assembler uses all operand types.  In addition to determining what
109 // kind of value an operand may be, non-concrete operand types capture the
110 // fact that an operand might be optional (may be absent, or present exactly
111 // once), or might occur zero or more times.
112 //
113 // Sometimes we also need to be able to express the fact that an operand
114 // is a member of an optional tuple of values.  In that case the first member
115 // would be optional, and the subsequent members would be required.
116 //
117 // NOTE: Although we don't promise binary compatibility, as a courtesy, please
118 // add new enum values at the end.
119 typedef enum spv_operand_type_t {
120   // A sentinel value.
121   SPV_OPERAND_TYPE_NONE = 0,
122 
123   // Set 1:  Operands that are IDs.
124   SPV_OPERAND_TYPE_ID,
125   SPV_OPERAND_TYPE_TYPE_ID,
126   SPV_OPERAND_TYPE_RESULT_ID,
127   SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID,  // SPIR-V Sec 3.25
128   SPV_OPERAND_TYPE_SCOPE_ID,             // SPIR-V Sec 3.27
129 
130   // Set 2:  Operands that are literal numbers.
131   SPV_OPERAND_TYPE_LITERAL_INTEGER,  // Always unsigned 32-bits.
132   // The Instruction argument to OpExtInst. It's an unsigned 32-bit literal
133   // number indicating which instruction to use from an extended instruction
134   // set.
135   SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER,
136   // The Opcode argument to OpSpecConstantOp. It determines the operation
137   // to be performed on constant operands to compute a specialization constant
138   // result.
139   SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER,
140   // A literal number whose format and size are determined by a previous operand
141   // in the same instruction.  It's a signed integer, an unsigned integer, or a
142   // floating point number.  It also has a specified bit width.  The width
143   // may be larger than 32, which would require such a typed literal value to
144   // occupy multiple SPIR-V words.
145   SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER,
146 
147   // Set 3:  The literal string operand type.
148   SPV_OPERAND_TYPE_LITERAL_STRING,
149 
150   // Set 4:  Operands that are a single word enumerated value.
151   SPV_OPERAND_TYPE_SOURCE_LANGUAGE,               // SPIR-V Sec 3.2
152   SPV_OPERAND_TYPE_EXECUTION_MODEL,               // SPIR-V Sec 3.3
153   SPV_OPERAND_TYPE_ADDRESSING_MODEL,              // SPIR-V Sec 3.4
154   SPV_OPERAND_TYPE_MEMORY_MODEL,                  // SPIR-V Sec 3.5
155   SPV_OPERAND_TYPE_EXECUTION_MODE,                // SPIR-V Sec 3.6
156   SPV_OPERAND_TYPE_STORAGE_CLASS,                 // SPIR-V Sec 3.7
157   SPV_OPERAND_TYPE_DIMENSIONALITY,                // SPIR-V Sec 3.8
158   SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE,       // SPIR-V Sec 3.9
159   SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE,           // SPIR-V Sec 3.10
160   SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT,          // SPIR-V Sec 3.11
161   SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER,           // SPIR-V Sec 3.12
162   SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE,       // SPIR-V Sec 3.13
163   SPV_OPERAND_TYPE_FP_ROUNDING_MODE,              // SPIR-V Sec 3.16
164   SPV_OPERAND_TYPE_LINKAGE_TYPE,                  // SPIR-V Sec 3.17
165   SPV_OPERAND_TYPE_ACCESS_QUALIFIER,              // SPIR-V Sec 3.18
166   SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE,  // SPIR-V Sec 3.19
167   SPV_OPERAND_TYPE_DECORATION,                    // SPIR-V Sec 3.20
168   SPV_OPERAND_TYPE_BUILT_IN,                      // SPIR-V Sec 3.21
169   SPV_OPERAND_TYPE_GROUP_OPERATION,               // SPIR-V Sec 3.28
170   SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS,              // SPIR-V Sec 3.29
171   SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO,         // SPIR-V Sec 3.30
172   SPV_OPERAND_TYPE_CAPABILITY,                    // SPIR-V Sec 3.31
173 
174   // NOTE: New concrete enum values should be added at the end.
175 
176   // Set 5:  Operands that are a single word bitmask.
177   // Sometimes a set bit indicates the instruction requires still more operands.
178   SPV_OPERAND_TYPE_IMAGE,                  // SPIR-V Sec 3.14
179   SPV_OPERAND_TYPE_FP_FAST_MATH_MODE,      // SPIR-V Sec 3.15
180   SPV_OPERAND_TYPE_SELECTION_CONTROL,      // SPIR-V Sec 3.22
181   SPV_OPERAND_TYPE_LOOP_CONTROL,           // SPIR-V Sec 3.23
182   SPV_OPERAND_TYPE_FUNCTION_CONTROL,       // SPIR-V Sec 3.24
183   SPV_OPERAND_TYPE_MEMORY_ACCESS,          // SPIR-V Sec 3.26
184   SPV_OPERAND_TYPE_FRAGMENT_SHADING_RATE,  // SPIR-V Sec 3.FSR
185 
186 // NOTE: New concrete enum values should be added at the end.
187 
188 // The "optional" and "variable"  operand types are only used internally by
189 // the assembler and the binary parser.
190 // There are two categories:
191 //    Optional : expands to 0 or 1 operand, like ? in regular expressions.
192 //    Variable : expands to 0, 1 or many operands or pairs of operands.
193 //               This is similar to * in regular expressions.
194 
195 // NOTE: These FIRST_* and LAST_* enum values are DEPRECATED.
196 // The concept of "optional" and "variable" operand types are only intended
197 // for use as an implementation detail of parsing SPIR-V, either in text or
198 // binary form.  Instead of using enum ranges, use characteristic function
199 // spvOperandIsConcrete.
200 // The use of enum value ranges in a public API makes it difficult to insert
201 // new values into a range without also breaking binary compatibility.
202 //
203 // Macros for defining bounds on optional and variable operand types.
204 // Any variable operand type is also optional.
205 // TODO(dneto): Remove SPV_OPERAND_TYPE_FIRST_* and SPV_OPERAND_TYPE_LAST_*
206 #define FIRST_OPTIONAL(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_OPTIONAL_TYPE = ENUM
207 #define FIRST_VARIABLE(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE = ENUM
208 #define LAST_VARIABLE(ENUM)                         \
209   ENUM, SPV_OPERAND_TYPE_LAST_VARIABLE_TYPE = ENUM, \
210         SPV_OPERAND_TYPE_LAST_OPTIONAL_TYPE = ENUM
211 
212   // An optional operand represents zero or one logical operands.
213   // In an instruction definition, this may only appear at the end of the
214   // operand types.
215   FIRST_OPTIONAL(SPV_OPERAND_TYPE_OPTIONAL_ID),
216   // An optional image operand type.
217   SPV_OPERAND_TYPE_OPTIONAL_IMAGE,
218   // An optional memory access type.
219   SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,
220   // An optional literal integer.
221   SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER,
222   // An optional literal number, which may be either integer or floating point.
223   SPV_OPERAND_TYPE_OPTIONAL_LITERAL_NUMBER,
224   // Like SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER, but optional, and integral.
225   SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER,
226   // An optional literal string.
227   SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING,
228   // An optional access qualifier
229   SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER,
230   // An optional context-independent value, or CIV.  CIVs are tokens that we can
231   // assemble regardless of where they occur -- literals, IDs, immediate
232   // integers, etc.
233   SPV_OPERAND_TYPE_OPTIONAL_CIV,
234 
235   // A variable operand represents zero or more logical operands.
236   // In an instruction definition, this may only appear at the end of the
237   // operand types.
238   FIRST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID),
239   SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER,
240   // A sequence of zero or more pairs of (typed literal integer, Id).
241   // Expands to zero or more:
242   //  (SPV_OPERAND_TYPE_TYPED_LITERAL_INTEGER, SPV_OPERAND_TYPE_ID)
243   // where the literal number must always be an integer of some sort.
244   SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID,
245   // A sequence of zero or more pairs of (Id, Literal integer)
246   LAST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER),
247 
248   // The following are concrete enum types from the DebugInfo extended
249   // instruction set.
250   SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS,  // DebugInfo Sec 3.2.  A mask.
251   SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING,  // DebugInfo Sec 3.3
252   SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE,                // DebugInfo Sec 3.4
253   SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER,                // DebugInfo Sec 3.5
254   SPV_OPERAND_TYPE_DEBUG_OPERATION,                     // DebugInfo Sec 3.6
255 
256   // The following are concrete enum types from the OpenCL.DebugInfo.100
257   // extended instruction set.
258   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS,  // Sec 3.2. A Mask
259   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING,  // Sec 3.3
260   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_COMPOSITE_TYPE,                // Sec 3.4
261   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_TYPE_QUALIFIER,                // Sec 3.5
262   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_OPERATION,                     // Sec 3.6
263   SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_IMPORTED_ENTITY,               // Sec 3.7
264 
265   // The following are concrete enum types from SPV_INTEL_float_controls2
266   // https://github.com/intel/llvm/blob/39fa9b0cbfbae88327118990a05c5b387b56d2ef/sycl/doc/extensions/SPIRV/SPV_INTEL_float_controls2.asciidoc
267   SPV_OPERAND_TYPE_FPDENORM_MODE,     // Sec 3.17 FP Denorm Mode
268   SPV_OPERAND_TYPE_FPOPERATION_MODE,  // Sec 3.18 FP Operation Mode
269   // A value enum from https://github.com/KhronosGroup/SPIRV-Headers/pull/177
270   SPV_OPERAND_TYPE_QUANTIZATION_MODES,
271   // A value enum from https://github.com/KhronosGroup/SPIRV-Headers/pull/177
272   SPV_OPERAND_TYPE_OVERFLOW_MODES,
273 
274   // Concrete operand types for the provisional Vulkan ray tracing feature.
275   SPV_OPERAND_TYPE_RAY_FLAGS,               // SPIR-V Sec 3.RF
276   SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION,  // SPIR-V Sec 3.RQIntersection
277   SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE,  // SPIR-V Sec
278                                                            // 3.RQCommitted
279   SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE,  // SPIR-V Sec
280                                                            // 3.RQCandidate
281 
282   // Concrete operand types for integer dot product.
283   // Packed vector format
284   SPV_OPERAND_TYPE_PACKED_VECTOR_FORMAT,  // SPIR-V Sec 3.x
285   // An optional packed vector format
286   SPV_OPERAND_TYPE_OPTIONAL_PACKED_VECTOR_FORMAT,
287 
288   // This is a sentinel value, and does not represent an operand type.
289   // It should come last.
290   SPV_OPERAND_TYPE_NUM_OPERAND_TYPES,
291 
292   SPV_FORCE_32_BIT_ENUM(spv_operand_type_t)
293 } spv_operand_type_t;
294 
295 // Returns true if the given type is concrete.
296 bool spvOperandIsConcrete(spv_operand_type_t type);
297 
298 // Returns true if the given type is concrete and also a mask.
299 bool spvOperandIsConcreteMask(spv_operand_type_t type);
300 
301 typedef enum spv_ext_inst_type_t {
302   SPV_EXT_INST_TYPE_NONE = 0,
303   SPV_EXT_INST_TYPE_GLSL_STD_450,
304   SPV_EXT_INST_TYPE_OPENCL_STD,
305   SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
306   SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
307   SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
308   SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
309   SPV_EXT_INST_TYPE_DEBUGINFO,
310   SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100,
311   SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
312   SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100,
313 
314   // Multiple distinct extended instruction set types could return this
315   // value, if they are prefixed with NonSemantic. and are otherwise
316   // unrecognised
317   SPV_EXT_INST_TYPE_NONSEMANTIC_UNKNOWN,
318 
319   SPV_FORCE_32_BIT_ENUM(spv_ext_inst_type_t)
320 } spv_ext_inst_type_t;
321 
322 // This determines at a high level the kind of a binary-encoded literal
323 // number, but not the bit width.
324 // In principle, these could probably be folded into new entries in
325 // spv_operand_type_t.  But then we'd have some special case differences
326 // between the assembler and disassembler.
327 typedef enum spv_number_kind_t {
328   SPV_NUMBER_NONE = 0,  // The default for value initialization.
329   SPV_NUMBER_UNSIGNED_INT,
330   SPV_NUMBER_SIGNED_INT,
331   SPV_NUMBER_FLOATING,
332 } spv_number_kind_t;
333 
334 typedef enum spv_text_to_binary_options_t {
335   SPV_TEXT_TO_BINARY_OPTION_NONE = SPV_BIT(0),
336   // Numeric IDs in the binary will have the same values as in the source.
337   // Non-numeric IDs are allocated by filling in the gaps, starting with 1
338   // and going up.
339   SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS = SPV_BIT(1),
340   SPV_FORCE_32_BIT_ENUM(spv_text_to_binary_options_t)
341 } spv_text_to_binary_options_t;
342 
343 typedef enum spv_binary_to_text_options_t {
344   SPV_BINARY_TO_TEXT_OPTION_NONE = SPV_BIT(0),
345   SPV_BINARY_TO_TEXT_OPTION_PRINT = SPV_BIT(1),
346   SPV_BINARY_TO_TEXT_OPTION_COLOR = SPV_BIT(2),
347   SPV_BINARY_TO_TEXT_OPTION_INDENT = SPV_BIT(3),
348   SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET = SPV_BIT(4),
349   // Do not output the module header as leading comments in the assembly.
350   SPV_BINARY_TO_TEXT_OPTION_NO_HEADER = SPV_BIT(5),
351   // Use friendly names where possible.  The heuristic may expand over
352   // time, but will use common names for scalar types, and debug names from
353   // OpName instructions.
354   SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES = SPV_BIT(6),
355   // Add some comments to the generated assembly
356   SPV_BINARY_TO_TEXT_OPTION_COMMENT = SPV_BIT(7),
357   SPV_FORCE_32_BIT_ENUM(spv_binary_to_text_options_t)
358 } spv_binary_to_text_options_t;
359 
360 // Constants
361 
362 // The default id bound is to the minimum value for the id limit
363 // in the spir-v specification under the section "Universal Limits".
364 const uint32_t kDefaultMaxIdBound = 0x3FFFFF;
365 
366 // Structures
367 
368 // Information about an operand parsed from a binary SPIR-V module.
369 // Note that the values are not included.  You still need access to the binary
370 // to extract the values.
371 typedef struct spv_parsed_operand_t {
372   // Location of the operand, in words from the start of the instruction.
373   uint16_t offset;
374   // Number of words occupied by this operand.
375   uint16_t num_words;
376   // The "concrete" operand type.  See the definition of spv_operand_type_t
377   // for details.
378   spv_operand_type_t type;
379   // If type is a literal number type, then number_kind says whether it's
380   // a signed integer, an unsigned integer, or a floating point number.
381   spv_number_kind_t number_kind;
382   // The number of bits for a literal number type.
383   uint32_t number_bit_width;
384 } spv_parsed_operand_t;
385 
386 // An instruction parsed from a binary SPIR-V module.
387 typedef struct spv_parsed_instruction_t {
388   // An array of words for this instruction, in native endianness.
389   const uint32_t* words;
390   // The number of words in this instruction.
391   uint16_t num_words;
392   uint16_t opcode;
393   // The extended instruction type, if opcode is OpExtInst.  Otherwise
394   // this is the "none" value.
395   spv_ext_inst_type_t ext_inst_type;
396   // The type id, or 0 if this instruction doesn't have one.
397   uint32_t type_id;
398   // The result id, or 0 if this instruction doesn't have one.
399   uint32_t result_id;
400   // The array of parsed operands.
401   const spv_parsed_operand_t* operands;
402   uint16_t num_operands;
403 } spv_parsed_instruction_t;
404 
405 typedef struct spv_const_binary_t {
406   const uint32_t* code;
407   const size_t wordCount;
408 } spv_const_binary_t;
409 
410 typedef struct spv_binary_t {
411   uint32_t* code;
412   size_t wordCount;
413 } spv_binary_t;
414 
415 typedef struct spv_text_t {
416   const char* str;
417   size_t length;
418 } spv_text_t;
419 
420 typedef struct spv_position_t {
421   size_t line;
422   size_t column;
423   size_t index;
424 } spv_position_t;
425 
426 typedef struct spv_diagnostic_t {
427   spv_position_t position;
428   char* error;
429   bool isTextSource;
430 } spv_diagnostic_t;
431 
432 // Opaque struct containing the context used to operate on a SPIR-V module.
433 // Its object is used by various translation API functions.
434 typedef struct spv_context_t spv_context_t;
435 
436 typedef struct spv_validator_options_t spv_validator_options_t;
437 
438 typedef struct spv_optimizer_options_t spv_optimizer_options_t;
439 
440 typedef struct spv_reducer_options_t spv_reducer_options_t;
441 
442 typedef struct spv_fuzzer_options_t spv_fuzzer_options_t;
443 
444 // Type Definitions
445 
446 typedef spv_const_binary_t* spv_const_binary;
447 typedef spv_binary_t* spv_binary;
448 typedef spv_text_t* spv_text;
449 typedef spv_position_t* spv_position;
450 typedef spv_diagnostic_t* spv_diagnostic;
451 typedef const spv_context_t* spv_const_context;
452 typedef spv_context_t* spv_context;
453 typedef spv_validator_options_t* spv_validator_options;
454 typedef const spv_validator_options_t* spv_const_validator_options;
455 typedef spv_optimizer_options_t* spv_optimizer_options;
456 typedef const spv_optimizer_options_t* spv_const_optimizer_options;
457 typedef spv_reducer_options_t* spv_reducer_options;
458 typedef const spv_reducer_options_t* spv_const_reducer_options;
459 typedef spv_fuzzer_options_t* spv_fuzzer_options;
460 typedef const spv_fuzzer_options_t* spv_const_fuzzer_options;
461 
462 // Platform API
463 
464 // Returns the SPIRV-Tools software version as a null-terminated string.
465 // The contents of the underlying storage is valid for the remainder of
466 // the process.
467 SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionString(void);
468 // Returns a null-terminated string containing the name of the project,
469 // the software version string, and commit details.
470 // The contents of the underlying storage is valid for the remainder of
471 // the process.
472 SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionDetailsString(void);
473 
474 // Certain target environments impose additional restrictions on SPIR-V, so it's
475 // often necessary to specify which one applies.  SPV_ENV_UNIVERSAL_* implies an
476 // environment-agnostic SPIR-V.
477 //
478 // When an API method needs to derive a SPIR-V version from a target environment
479 // (from the spv_context object), the method will choose the highest version of
480 // SPIR-V supported by the target environment.  Examples:
481 //    SPV_ENV_VULKAN_1_0           ->  SPIR-V 1.0
482 //    SPV_ENV_VULKAN_1_1           ->  SPIR-V 1.3
483 //    SPV_ENV_VULKAN_1_1_SPIRV_1_4 ->  SPIR-V 1.4
484 //    SPV_ENV_VULKAN_1_2           ->  SPIR-V 1.5
485 //    SPV_ENV_VULKAN_1_3           ->  SPIR-V 1.6
486 // Consult the description of API entry points for specific rules.
487 typedef enum {
488   SPV_ENV_UNIVERSAL_1_0,  // SPIR-V 1.0 latest revision, no other restrictions.
489   SPV_ENV_VULKAN_1_0,     // Vulkan 1.0 latest revision.
490   SPV_ENV_UNIVERSAL_1_1,  // SPIR-V 1.1 latest revision, no other restrictions.
491   SPV_ENV_OPENCL_2_1,     // OpenCL Full Profile 2.1 latest revision.
492   SPV_ENV_OPENCL_2_2,     // OpenCL Full Profile 2.2 latest revision.
493   SPV_ENV_OPENGL_4_0,     // OpenGL 4.0 plus GL_ARB_gl_spirv, latest revisions.
494   SPV_ENV_OPENGL_4_1,     // OpenGL 4.1 plus GL_ARB_gl_spirv, latest revisions.
495   SPV_ENV_OPENGL_4_2,     // OpenGL 4.2 plus GL_ARB_gl_spirv, latest revisions.
496   SPV_ENV_OPENGL_4_3,     // OpenGL 4.3 plus GL_ARB_gl_spirv, latest revisions.
497   // There is no variant for OpenGL 4.4.
498   SPV_ENV_OPENGL_4_5,     // OpenGL 4.5 plus GL_ARB_gl_spirv, latest revisions.
499   SPV_ENV_UNIVERSAL_1_2,  // SPIR-V 1.2, latest revision, no other restrictions.
500   SPV_ENV_OPENCL_1_2,     // OpenCL Full Profile 1.2 plus cl_khr_il_program,
501                           // latest revision.
502   SPV_ENV_OPENCL_EMBEDDED_1_2,  // OpenCL Embedded Profile 1.2 plus
503                                 // cl_khr_il_program, latest revision.
504   SPV_ENV_OPENCL_2_0,  // OpenCL Full Profile 2.0 plus cl_khr_il_program,
505                        // latest revision.
506   SPV_ENV_OPENCL_EMBEDDED_2_0,  // OpenCL Embedded Profile 2.0 plus
507                                 // cl_khr_il_program, latest revision.
508   SPV_ENV_OPENCL_EMBEDDED_2_1,  // OpenCL Embedded Profile 2.1 latest revision.
509   SPV_ENV_OPENCL_EMBEDDED_2_2,  // OpenCL Embedded Profile 2.2 latest revision.
510   SPV_ENV_UNIVERSAL_1_3,  // SPIR-V 1.3 latest revision, no other restrictions.
511   SPV_ENV_VULKAN_1_1,     // Vulkan 1.1 latest revision.
512   SPV_ENV_WEBGPU_0,       // DEPRECATED, may be removed in the future.
513   SPV_ENV_UNIVERSAL_1_4,  // SPIR-V 1.4 latest revision, no other restrictions.
514 
515   // Vulkan 1.1 with VK_KHR_spirv_1_4, i.e. SPIR-V 1.4 binary.
516   SPV_ENV_VULKAN_1_1_SPIRV_1_4,
517 
518   SPV_ENV_UNIVERSAL_1_5,  // SPIR-V 1.5 latest revision, no other restrictions.
519   SPV_ENV_VULKAN_1_2,     // Vulkan 1.2 latest revision.
520 
521   SPV_ENV_UNIVERSAL_1_6,  // SPIR-V 1.6 latest revision, no other restrictions.
522   SPV_ENV_VULKAN_1_3,     // Vulkan 1.3 latest revision.
523 
524   SPV_ENV_MAX  // Keep this as the last enum value.
525 } spv_target_env;
526 
527 // SPIR-V Validator can be parameterized with the following Universal Limits.
528 typedef enum {
529   spv_validator_limit_max_struct_members,
530   spv_validator_limit_max_struct_depth,
531   spv_validator_limit_max_local_variables,
532   spv_validator_limit_max_global_variables,
533   spv_validator_limit_max_switch_branches,
534   spv_validator_limit_max_function_args,
535   spv_validator_limit_max_control_flow_nesting_depth,
536   spv_validator_limit_max_access_chain_indexes,
537   spv_validator_limit_max_id_bound,
538 } spv_validator_limit;
539 
540 // Returns a string describing the given SPIR-V target environment.
541 SPIRV_TOOLS_EXPORT const char* spvTargetEnvDescription(spv_target_env env);
542 
543 // Parses s into *env and returns true if successful.  If unparsable, returns
544 // false and sets *env to SPV_ENV_UNIVERSAL_1_0.
545 SPIRV_TOOLS_EXPORT bool spvParseTargetEnv(const char* s, spv_target_env* env);
546 
547 // Determines the target env value with the least features but which enables
548 // the given Vulkan and SPIR-V versions. If such a target is supported, returns
549 // true and writes the value to |env|, otherwise returns false.
550 //
551 // The Vulkan version is given as an unsigned 32-bit number as specified in
552 // Vulkan section "29.2.1 Version Numbers": the major version number appears
553 // in bits 22 to 21, and the minor version is in bits 12 to 21.  The SPIR-V
554 // version is given in the SPIR-V version header word: major version in bits
555 // 16 to 23, and minor version in bits 8 to 15.
556 SPIRV_TOOLS_EXPORT bool spvParseVulkanEnv(uint32_t vulkan_ver,
557                                           uint32_t spirv_ver,
558                                           spv_target_env* env);
559 
560 // Creates a context object for most of the SPIRV-Tools API.
561 // Returns null if env is invalid.
562 //
563 // See specific API calls for how the target environment is interpreted
564 // (particularly assembly and validation).
565 SPIRV_TOOLS_EXPORT spv_context spvContextCreate(spv_target_env env);
566 
567 // Destroys the given context object.
568 SPIRV_TOOLS_EXPORT void spvContextDestroy(spv_context context);
569 
570 // Creates a Validator options object with default options. Returns a valid
571 // options object. The object remains valid until it is passed into
572 // spvValidatorOptionsDestroy.
573 SPIRV_TOOLS_EXPORT spv_validator_options spvValidatorOptionsCreate(void);
574 
575 // Destroys the given Validator options object.
576 SPIRV_TOOLS_EXPORT void spvValidatorOptionsDestroy(
577     spv_validator_options options);
578 
579 // Records the maximum Universal Limit that is considered valid in the given
580 // Validator options object. <options> argument must be a valid options object.
581 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniversalLimit(
582     spv_validator_options options, spv_validator_limit limit_type,
583     uint32_t limit);
584 
585 // Record whether or not the validator should relax the rules on types for
586 // stores to structs.  When relaxed, it will allow a type mismatch as long as
587 // the types are structs with the same layout.  Two structs have the same layout
588 // if
589 //
590 // 1) the members of the structs are either the same type or are structs with
591 // same layout, and
592 //
593 // 2) the decorations that affect the memory layout are identical for both
594 // types.  Other decorations are not relevant.
595 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxStoreStruct(
596     spv_validator_options options, bool val);
597 
598 // Records whether or not the validator should relax the rules on pointer usage
599 // in logical addressing mode.
600 //
601 // When relaxed, it will allow the following usage cases of pointers:
602 // 1) OpVariable allocating an object whose type is a pointer type
603 // 2) OpReturnValue returning a pointer value
604 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxLogicalPointer(
605     spv_validator_options options, bool val);
606 
607 // Records whether or not the validator should relax the rules because it is
608 // expected that the optimizations will make the code legal.
609 //
610 // When relaxed, it will allow the following:
611 // 1) It will allow relaxed logical pointers.  Setting this option will also
612 //    set that option.
613 // 2) Pointers that are pass as parameters to function calls do not have to
614 //    match the storage class of the formal parameter.
615 // 3) Pointers that are actual parameters on function calls do not have to point
616 //    to the same type pointed as the formal parameter.  The types just need to
617 //    logically match.
618 // 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
619 //    for a first argument.
620 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetBeforeHlslLegalization(
621     spv_validator_options options, bool val);
622 
623 // Records whether the validator should use "relaxed" block layout rules.
624 // Relaxed layout rules are described by Vulkan extension
625 // VK_KHR_relaxed_block_layout, and they affect uniform blocks, storage blocks,
626 // and push constants.
627 //
628 // This is enabled by default when targeting Vulkan 1.1 or later.
629 // Relaxed layout is more permissive than the default rules in Vulkan 1.0.
630 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxBlockLayout(
631     spv_validator_options options, bool val);
632 
633 // Records whether the validator should use standard block layout rules for
634 // uniform blocks.
635 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniformBufferStandardLayout(
636     spv_validator_options options, bool val);
637 
638 // Records whether the validator should use "scalar" block layout rules.
639 // Scalar layout rules are more permissive than relaxed block layout.
640 //
641 // See Vulkan extension VK_EXT_scalar_block_layout.  The scalar alignment is
642 // defined as follows:
643 // - scalar alignment of a scalar is the scalar size
644 // - scalar alignment of a vector is the scalar alignment of its component
645 // - scalar alignment of a matrix is the scalar alignment of its component
646 // - scalar alignment of an array is the scalar alignment of its element
647 // - scalar alignment of a struct is the max scalar alignment among its
648 //   members
649 //
650 // For a struct in Uniform, StorageClass, or PushConstant:
651 // - a member Offset must be a multiple of the member's scalar alignment
652 // - ArrayStride or MatrixStride must be a multiple of the array or matrix
653 //   scalar alignment
654 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetScalarBlockLayout(
655     spv_validator_options options, bool val);
656 
657 // Records whether the validator should use "scalar" block layout
658 // rules (as defined above) for Workgroup blocks.  See Vulkan
659 // extension VK_KHR_workgroup_memory_explicit_layout.
660 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetWorkgroupScalarBlockLayout(
661     spv_validator_options options, bool val);
662 
663 // Records whether or not the validator should skip validating standard
664 // uniform/storage block layout.
665 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetSkipBlockLayout(
666     spv_validator_options options, bool val);
667 
668 // Records whether or not the validator should allow the LocalSizeId
669 // decoration where the environment otherwise would not allow it.
670 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowLocalSizeId(
671     spv_validator_options options, bool val);
672 
673 // Whether friendly names should be used in validation error messages.
674 SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetFriendlyNames(
675     spv_validator_options options, bool val);
676 
677 // Creates an optimizer options object with default options. Returns a valid
678 // options object. The object remains valid until it is passed into
679 // |spvOptimizerOptionsDestroy|.
680 SPIRV_TOOLS_EXPORT spv_optimizer_options spvOptimizerOptionsCreate(void);
681 
682 // Destroys the given optimizer options object.
683 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsDestroy(
684     spv_optimizer_options options);
685 
686 // Records whether or not the optimizer should run the validator before
687 // optimizing.  If |val| is true, the validator will be run.
688 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetRunValidator(
689     spv_optimizer_options options, bool val);
690 
691 // Records the validator options that should be passed to the validator if it is
692 // run.
693 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetValidatorOptions(
694     spv_optimizer_options options, spv_validator_options val);
695 
696 // Records the maximum possible value for the id bound.
697 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetMaxIdBound(
698     spv_optimizer_options options, uint32_t val);
699 
700 // Records whether all bindings within the module should be preserved.
701 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetPreserveBindings(
702     spv_optimizer_options options, bool val);
703 
704 // Records whether all specialization constants within the module
705 // should be preserved.
706 SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetPreserveSpecConstants(
707     spv_optimizer_options options, bool val);
708 
709 // Creates a reducer options object with default options. Returns a valid
710 // options object. The object remains valid until it is passed into
711 // |spvReducerOptionsDestroy|.
712 SPIRV_TOOLS_EXPORT spv_reducer_options spvReducerOptionsCreate(void);
713 
714 // Destroys the given reducer options object.
715 SPIRV_TOOLS_EXPORT void spvReducerOptionsDestroy(spv_reducer_options options);
716 
717 // Sets the maximum number of reduction steps that should run before the reducer
718 // gives up.
719 SPIRV_TOOLS_EXPORT void spvReducerOptionsSetStepLimit(
720     spv_reducer_options options, uint32_t step_limit);
721 
722 // Sets the fail-on-validation-error option; if true, the reducer will return
723 // kStateInvalid if a reduction step yields a state that fails SPIR-V
724 // validation. Otherwise, an invalid state is treated as uninteresting and the
725 // reduction backtracks and continues.
726 SPIRV_TOOLS_EXPORT void spvReducerOptionsSetFailOnValidationError(
727     spv_reducer_options options, bool fail_on_validation_error);
728 
729 // Sets the function that the reducer should target.  If set to zero the reducer
730 // will target all functions as well as parts of the module that lie outside
731 // functions.  Otherwise the reducer will restrict reduction to the function
732 // with result id |target_function|, which is required to exist.
733 SPIRV_TOOLS_EXPORT void spvReducerOptionsSetTargetFunction(
734     spv_reducer_options options, uint32_t target_function);
735 
736 // Creates a fuzzer options object with default options. Returns a valid
737 // options object. The object remains valid until it is passed into
738 // |spvFuzzerOptionsDestroy|.
739 SPIRV_TOOLS_EXPORT spv_fuzzer_options spvFuzzerOptionsCreate(void);
740 
741 // Destroys the given fuzzer options object.
742 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsDestroy(spv_fuzzer_options options);
743 
744 // Enables running the validator after every transformation is applied during
745 // a replay.
746 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableReplayValidation(
747     spv_fuzzer_options options);
748 
749 // Sets the seed with which the random number generator used by the fuzzer
750 // should be initialized.
751 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetRandomSeed(
752     spv_fuzzer_options options, uint32_t seed);
753 
754 // Sets the range of transformations that should be applied during replay: 0
755 // means all transformations, +N means the first N transformations, -N means all
756 // except the final N transformations.
757 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetReplayRange(
758     spv_fuzzer_options options, int32_t replay_range);
759 
760 // Sets the maximum number of steps that the shrinker should take before giving
761 // up.
762 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetShrinkerStepLimit(
763     spv_fuzzer_options options, uint32_t shrinker_step_limit);
764 
765 // Enables running the validator after every pass is applied during a fuzzing
766 // run.
767 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableFuzzerPassValidation(
768     spv_fuzzer_options options);
769 
770 // Enables all fuzzer passes during a fuzzing run (instead of a random subset
771 // of passes).
772 SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableAllPasses(
773     spv_fuzzer_options options);
774 
775 // Encodes the given SPIR-V assembly text to its binary representation. The
776 // length parameter specifies the number of bytes for text. Encoded binary will
777 // be stored into *binary. Any error will be written into *diagnostic if
778 // diagnostic is non-null, otherwise the context's message consumer will be
779 // used. The generated binary is independent of the context and may outlive it.
780 // The SPIR-V binary version is set to the highest version of SPIR-V supported
781 // by the context's target environment.
782 SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinary(const spv_const_context context,
783                                                 const char* text,
784                                                 const size_t length,
785                                                 spv_binary* binary,
786                                                 spv_diagnostic* diagnostic);
787 
788 // Encodes the given SPIR-V assembly text to its binary representation. Same as
789 // spvTextToBinary but with options. The options parameter is a bit field of
790 // spv_text_to_binary_options_t.
791 SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinaryWithOptions(
792     const spv_const_context context, const char* text, const size_t length,
793     const uint32_t options, spv_binary* binary, spv_diagnostic* diagnostic);
794 
795 // Frees an allocated text stream. This is a no-op if the text parameter
796 // is a null pointer.
797 SPIRV_TOOLS_EXPORT void spvTextDestroy(spv_text text);
798 
799 // Decodes the given SPIR-V binary representation to its assembly text. The
800 // word_count parameter specifies the number of words for binary. The options
801 // parameter is a bit field of spv_binary_to_text_options_t. Decoded text will
802 // be stored into *text. Any error will be written into *diagnostic if
803 // diagnostic is non-null, otherwise the context's message consumer will be
804 // used.
805 SPIRV_TOOLS_EXPORT spv_result_t spvBinaryToText(const spv_const_context context,
806                                                 const uint32_t* binary,
807                                                 const size_t word_count,
808                                                 const uint32_t options,
809                                                 spv_text* text,
810                                                 spv_diagnostic* diagnostic);
811 
812 // Frees a binary stream from memory. This is a no-op if binary is a null
813 // pointer.
814 SPIRV_TOOLS_EXPORT void spvBinaryDestroy(spv_binary binary);
815 
816 // Validates a SPIR-V binary for correctness. Any errors will be written into
817 // *diagnostic if diagnostic is non-null, otherwise the context's message
818 // consumer will be used.
819 //
820 // Validate for SPIR-V spec rules for the SPIR-V version named in the
821 // binary's header (at word offset 1).  Additionally, if the context target
822 // environment is a client API (such as Vulkan 1.1), then validate for that
823 // client API version, to the extent that it is verifiable from data in the
824 // binary itself.
825 SPIRV_TOOLS_EXPORT spv_result_t spvValidate(const spv_const_context context,
826                                             const spv_const_binary binary,
827                                             spv_diagnostic* diagnostic);
828 
829 // Validates a SPIR-V binary for correctness. Uses the provided Validator
830 // options. Any errors will be written into *diagnostic if diagnostic is
831 // non-null, otherwise the context's message consumer will be used.
832 //
833 // Validate for SPIR-V spec rules for the SPIR-V version named in the
834 // binary's header (at word offset 1).  Additionally, if the context target
835 // environment is a client API (such as Vulkan 1.1), then validate for that
836 // client API version, to the extent that it is verifiable from data in the
837 // binary itself, or in the validator options.
838 SPIRV_TOOLS_EXPORT spv_result_t spvValidateWithOptions(
839     const spv_const_context context, const spv_const_validator_options options,
840     const spv_const_binary binary, spv_diagnostic* diagnostic);
841 
842 // Validates a raw SPIR-V binary for correctness. Any errors will be written
843 // into *diagnostic if diagnostic is non-null, otherwise the context's message
844 // consumer will be used.
845 SPIRV_TOOLS_EXPORT spv_result_t
846 spvValidateBinary(const spv_const_context context, const uint32_t* words,
847                   const size_t num_words, spv_diagnostic* diagnostic);
848 
849 // Creates a diagnostic object. The position parameter specifies the location in
850 // the text/binary stream. The message parameter, copied into the diagnostic
851 // object, contains the error message to display.
852 SPIRV_TOOLS_EXPORT spv_diagnostic
853 spvDiagnosticCreate(const spv_position position, const char* message);
854 
855 // Destroys a diagnostic object.  This is a no-op if diagnostic is a null
856 // pointer.
857 SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
858 
859 // Prints the diagnostic to stderr.
860 SPIRV_TOOLS_EXPORT spv_result_t
861 spvDiagnosticPrint(const spv_diagnostic diagnostic);
862 
863 // Gets the name of an instruction, without the "Op" prefix.
864 SPIRV_TOOLS_EXPORT const char* spvOpcodeString(const uint32_t opcode);
865 
866 // The binary parser interface.
867 
868 // A pointer to a function that accepts a parsed SPIR-V header.
869 // The integer arguments are the 32-bit words from the header, as specified
870 // in SPIR-V 1.0 Section 2.3 Table 1.
871 // The function should return SPV_SUCCESS if parsing should continue.
872 typedef spv_result_t (*spv_parsed_header_fn_t)(
873     void* user_data, spv_endianness_t endian, uint32_t magic, uint32_t version,
874     uint32_t generator, uint32_t id_bound, uint32_t reserved);
875 
876 // A pointer to a function that accepts a parsed SPIR-V instruction.
877 // The parsed_instruction value is transient: it may be overwritten
878 // or released immediately after the function has returned.  That also
879 // applies to the words array member of the parsed instruction.  The
880 // function should return SPV_SUCCESS if and only if parsing should
881 // continue.
882 typedef spv_result_t (*spv_parsed_instruction_fn_t)(
883     void* user_data, const spv_parsed_instruction_t* parsed_instruction);
884 
885 // Parses a SPIR-V binary, specified as counted sequence of 32-bit words.
886 // Parsing feedback is provided via two callbacks provided as function
887 // pointers.  Each callback function pointer can be a null pointer, in
888 // which case it is never called.  Otherwise, in a valid parse the
889 // parsed-header callback is called once, and then the parsed-instruction
890 // callback once for each instruction in the stream.  The user_data parameter
891 // is supplied as context to the callbacks.  Returns SPV_SUCCESS on successful
892 // parse where the callbacks always return SPV_SUCCESS.  For an invalid parse,
893 // returns a status code other than SPV_SUCCESS, and if diagnostic is non-null
894 // also emits a diagnostic. If diagnostic is null the context's message consumer
895 // will be used to emit any errors. If a callback returns anything other than
896 // SPV_SUCCESS, then that status code is returned, no further callbacks are
897 // issued, and no additional diagnostics are emitted.
898 SPIRV_TOOLS_EXPORT spv_result_t spvBinaryParse(
899     const spv_const_context context, void* user_data, const uint32_t* words,
900     const size_t num_words, spv_parsed_header_fn_t parse_header,
901     spv_parsed_instruction_fn_t parse_instruction, spv_diagnostic* diagnostic);
902 
903 #ifdef __cplusplus
904 }
905 #endif
906 
907 #endif  // INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
908