From 0b9816813b99c6621da095d8e633d3a25835143d Mon Sep 17 00:00:00 2001 From: David Neto Date: Tue, 27 Oct 2015 15:51:34 -0400 Subject: [PATCH] Hide spvBinaryHeaderSet with its only client. Also rename it to SetHeader since it's not part of the "binary" API. --- source/binary.cpp | 13 ------------- source/binary.h | 8 -------- source/text.cpp | 22 ++++++++++++++++++++-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index de29106..4213bea 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -113,19 +113,6 @@ spv_result_t spvBinaryHeaderGet(const spv_binary binary, return SPV_SUCCESS; } -spv_result_t spvBinaryHeaderSet(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; - - 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 - - return SPV_SUCCESS; -} - // TODO(dneto): This API is not powerful enough in the case that the // number and type of operands are not known until partway through parsing // the operation. This happens when enum operands might have different number diff --git a/source/binary.h b/source/binary.h index b78a163..ad542cf 100644 --- a/source/binary.h +++ b/source/binary.h @@ -76,14 +76,6 @@ spv_result_t spvBinaryHeaderGet(const spv_binary binary, const spv_endianness_t endian, spv_header_t *pHeader); -/// @brief Populate a binary stream with this generators header -/// -/// @param[in,out] binary the binary stream -/// @param[in] bound the upper ID bound -/// -/// @return result code -spv_result_t spvBinaryHeaderSet(spv_binary binary, const uint32_t bound); - /// @brief Determine the type of the desired operand /// /// @param[in] word the operand value diff --git a/source/text.cpp b/source/text.cpp index 8853ed2..8d60a50 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -612,6 +612,25 @@ spv_result_t spvTextEncodeOpcode(const libspirv::AssemblyGrammar& grammar, namespace { +/// @brief Populate a binary stream with this generator's header. +/// +/// @param[in,out] binary the binary stream +/// @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; + + 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 + + return SPV_SUCCESS; +} + // Translates a given assembly language module into binary form. // If a diagnostic is generated, it is not yet marked as being // for a text-based input. @@ -673,8 +692,7 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar, binary->code = data; binary->wordCount = totalSize; - spv_result_t error = spvBinaryHeaderSet(binary, context.getBound()); - if (error) { + if (auto error = SetHeader(binary, context.getBound())) { spvBinaryDestroy(binary); return error; } -- 2.7.4