#ifndef LIBSPIRV_LIBSPIRV_LIBSPIRV_H_
#define LIBSPIRV_LIBSPIRV_LIBSPIRV_H_
-#include <headers/spirv.h>
-#include <headers/spirv_operands.hpp>
#include <headers/GLSL.std.450.h>
#include <headers/OpenCL.std.h>
+#include <headers/spirv.h>
+#include <headers/spirv_operands.hpp>
#ifdef __cplusplus
using namespace spv;
} spv_ext_inst_table_t;
typedef struct spv_binary_t {
- uint32_t* code;
+ uint32_t const* code;
uint64_t wordCount;
} spv_binary_t;
/// @param[out] pDiagnostic contains diagnostic on failure
///
/// @return result code
-spv_result_t spvBinaryToText(uint32_t* binary, const uint64_t wordCount,
+spv_result_t spvBinaryToText(uint32_t const* binary, const uint64_t wordCount,
const uint32_t options,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
///
/// @return result code
spv_result_t spvBinaryToTextWithFormat(
- uint32_t* binary, const uint64_t wordCount, const uint32_t options,
+ uint32_t const* binary, const uint64_t wordCount, const uint32_t options,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format,
spv_text* pText, spv_diagnostic* pDiagnostic);
}
spv_result_t spvBinaryToTextWithFormat(
- uint32_t* code, const uint64_t wordCount, const uint32_t options,
+ uint32_t const* code, const uint64_t wordCount, const uint32_t options,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format,
spv_text* pText, spv_diagnostic* pDiagnostic) {
#include "libspirv/libspirv.h"
-spv_result_t spvBinaryToText(uint32_t* code, const uint64_t wordCount,
+spv_result_t spvBinaryToText(uint32_t const* code, const uint64_t wordCount,
const uint32_t options,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
namespace {
-/// @brief Populate a binary stream with this generator's header.
+/// @brief Populate a binary stream's words with this generator's header.
///
-/// @param[in,out] binary the binary stream
+/// @param[in,out] words the array of words
/// @param[in] bound the upper ID bound
///
/// @return result code
-spv_result_t SetHeader(spv_binary_t* binary, const uint32_t bound) {
- if (!binary) return SPV_ERROR_INVALID_BINARY;
- if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY;
+spv_result_t SetHeader(uint32_t* words, const uint32_t bound) {
+ if (!words) return SPV_ERROR_INVALID_BINARY;
- binary->code[SPV_INDEX_MAGIC_NUMBER] = SPV_MAGIC_NUMBER;
- binary->code[SPV_INDEX_VERSION_NUMBER] = SPV_VERSION_NUMBER;
- binary->code[SPV_INDEX_GENERATOR_NUMBER] = SPV_GENERATOR_KHRONOS;
- binary->code[SPV_INDEX_BOUND] = bound;
- binary->code[SPV_INDEX_SCHEMA] = 0; // NOTE: Reserved
+ words[SPV_INDEX_MAGIC_NUMBER] = SPV_MAGIC_NUMBER;
+ words[SPV_INDEX_VERSION_NUMBER] = SPV_VERSION_NUMBER;
+ words[SPV_INDEX_GENERATOR_NUMBER] = SPV_GENERATOR_KHRONOS;
+ words[SPV_INDEX_BOUND] = bound;
+ words[SPV_INDEX_SCHEMA] = 0; // NOTE: Reserved
return SPV_SUCCESS;
}
currentIndex += inst.words.size();
}
+ if (auto error = SetHeader(data, context.getBound()))
+ return error;
+
spv_binary binary = new spv_binary_t();
if (!binary) {
delete[] data;
binary->code = data;
binary->wordCount = totalSize;
- if (auto error = SetHeader(binary, context.getBound())) {
- spvBinaryDestroy(binary);
- return error;
- }
-
*pBinary = binary;
return SPV_SUCCESS;