From e4945def956bb0415a646d92dfa1defd0353a083 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 28 Oct 2015 13:50:32 -0400 Subject: [PATCH] A spv_binary_t points to const code words. --- include/libspirv/libspirv.h | 10 +++++----- source/binary.cpp | 2 +- source/disassemble.cpp | 2 +- source/text.cpp | 27 ++++++++++++--------------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/libspirv/libspirv.h b/include/libspirv/libspirv.h index 5713a57..300c0b2 100644 --- a/include/libspirv/libspirv.h +++ b/include/libspirv/libspirv.h @@ -27,10 +27,10 @@ #ifndef LIBSPIRV_LIBSPIRV_LIBSPIRV_H_ #define LIBSPIRV_LIBSPIRV_LIBSPIRV_H_ -#include -#include #include #include +#include +#include #ifdef __cplusplus using namespace spv; @@ -354,7 +354,7 @@ typedef struct spv_ext_inst_table_t { } spv_ext_inst_table_t; typedef struct spv_binary_t { - uint32_t* code; + uint32_t const* code; uint64_t wordCount; } spv_binary_t; @@ -473,7 +473,7 @@ void spvTextDestroy(spv_text text); /// @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, @@ -494,7 +494,7 @@ spv_result_t spvBinaryToText(uint32_t* binary, const uint64_t wordCount, /// /// @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); diff --git a/source/binary.cpp b/source/binary.cpp index 330e692..8698b27 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -502,7 +502,7 @@ spv_result_t spvBinaryDecodeOpcode( } 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) { diff --git a/source/disassemble.cpp b/source/disassemble.cpp index 90a6181..8856924 100644 --- a/source/disassemble.cpp +++ b/source/disassemble.cpp @@ -32,7 +32,7 @@ #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, diff --git a/source/text.cpp b/source/text.cpp index a79699d..9e9104b 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -613,21 +613,20 @@ spv_result_t spvTextEncodeOpcode(const libspirv::AssemblyGrammar& grammar, 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; } @@ -686,6 +685,9 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar, currentIndex += inst.words.size(); } + if (auto error = SetHeader(data, context.getBound())) + return error; + spv_binary binary = new spv_binary_t(); if (!binary) { delete[] data; @@ -694,11 +696,6 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar, binary->code = data; binary->wordCount = totalSize; - if (auto error = SetHeader(binary, context.getBound())) { - spvBinaryDestroy(binary); - return error; - } - *pBinary = binary; return SPV_SUCCESS; -- 2.7.4