Fixed warnings on windows and constness of spv_binary.
Replaced uint64_t with size_t in the places that make sense and
added spv_const_binary{,_t} to allow the interface to accept non
modifiable spirv where appropriate.
diff --git a/include/libspirv/libspirv.h b/include/libspirv/libspirv.h
old mode 100644
new mode 100755
index b194160..e724ff1
--- a/include/libspirv/libspirv.h
+++ b/include/libspirv/libspirv.h
@@ -380,19 +380,25 @@
} spv_ext_inst_table_t;
typedef struct spv_binary_t {
- const uint32_t* code;
- uint64_t wordCount;
+ uint32_t* code;
+ size_t wordCount;
} spv_binary_t;
+typedef struct spv_const_binary_t {
+ const uint32_t* code;
+ const size_t wordCount;
+} spv_const_binary_t;
+
+
typedef struct spv_text_t {
const char* str;
- uint64_t length;
+ size_t length;
} spv_text_t;
typedef struct spv_position_t {
- uint64_t line;
- uint64_t column;
- uint64_t index;
+ size_t line;
+ size_t column;
+ size_t index;
} spv_position_t;
typedef struct spv_diagnostic_t {
@@ -409,6 +415,7 @@
typedef const spv_operand_table_t* spv_operand_table;
typedef const spv_ext_inst_desc_t* spv_ext_inst_desc;
typedef const spv_ext_inst_table_t* spv_ext_inst_table;
+typedef spv_const_binary_t* spv_const_binary;
typedef spv_binary_t* spv_binary;
typedef spv_text_t* spv_text;
typedef spv_position_t* spv_position;
@@ -452,7 +459,7 @@
/// @param[out] pDiagnostic contains diagnostic on failure
///
/// @return result code
-spv_result_t spvTextToBinary(const char* text, const uint64_t length,
+spv_result_t spvTextToBinary(const char* text, const size_t length,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable,
@@ -505,7 +512,7 @@
/// @param[out] pDiagnostic contains diagnostic on failure
///
/// @return result code
-spv_result_t spvValidate(const spv_binary binary,
+spv_result_t spvValidate(const spv_const_binary binary,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable,
diff --git a/source/binary.cpp b/source/binary.cpp
old mode 100644
new mode 100755
index 699f6b0..5e4c732
--- a/source/binary.cpp
+++ b/source/binary.cpp
@@ -39,7 +39,7 @@
#include "opcode.h"
#include "operand.h"
-spv_result_t spvBinaryHeaderGet(const spv_binary binary,
+spv_result_t spvBinaryHeaderGet(const spv_const_binary binary,
const spv_endianness_t endian,
spv_header_t* pHeader) {
if (!binary->code) return SPV_ERROR_INVALID_BINARY;
@@ -241,7 +241,7 @@
<< " words instead of " << SPV_INDEX_INSTRUCTION;
// Check the magic number and detect the module's endianness.
- spv_binary_t binary = {_.words, _.num_words}; // Can't make this const. :-(
+ spv_const_binary_t binary{_.words, _.num_words};
if (spvBinaryEndianness(&binary, &_.endian)) {
return diagnostic() << "Invalid SPIR-V magic number '" << std::hex
<< _.words[0] << "'.";
@@ -671,7 +671,7 @@
} // anonymous namespace
-spv_result_t spvBinaryParse(void* user_data, const uint32_t* const code,
+spv_result_t spvBinaryParse(void* user_data, const uint32_t* code,
const size_t num_words,
spv_parsed_header_fn_t parsed_header,
spv_parsed_instruction_fn_t parsed_instruction,
diff --git a/source/binary.h b/source/binary.h
old mode 100644
new mode 100755
index 08f0699..889716f
--- a/source/binary.h
+++ b/source/binary.h
@@ -107,7 +107,7 @@
// returns SPV_ERROR_INVALID_BINARY and emits a diagnostic. If a callback
// returns anything other than SPV_SUCCESS, then that error code is returned
// and parsing terminates early.
-spv_result_t spvBinaryParse(void* user_data, const uint32_t* const words,
+spv_result_t spvBinaryParse(void* user_data, const uint32_t* words,
const size_t num_words,
spv_parsed_header_fn_t parse_header,
spv_parsed_instruction_fn_t parse_instruction,
@@ -124,7 +124,7 @@
/// @param[out] pHeader the returned header
///
/// @return result code
-spv_result_t spvBinaryHeaderGet(const spv_binary binary,
+spv_result_t spvBinaryHeaderGet(const spv_const_binary binary,
const spv_endianness_t endian,
spv_header_t* pHeader);
diff --git a/source/endian.cpp b/source/endian.cpp
old mode 100644
new mode 100755
index 44d9ac6..e0b2b2b
--- a/source/endian.cpp
+++ b/source/endian.cpp
@@ -56,7 +56,7 @@
return (uint64_t(spvFixWord(high, endian)) << 32) | spvFixWord(low, endian);
}
-spv_result_t spvBinaryEndianness(const spv_binary binary,
+spv_result_t spvBinaryEndianness(spv_const_binary binary,
spv_endianness_t* pEndian) {
if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY;
if (!pEndian) return SPV_ERROR_INVALID_POINTER;
diff --git a/source/endian.h b/source/endian.h
old mode 100644
new mode 100755
index e03eeb2..c5c097a
--- a/source/endian.h
+++ b/source/endian.h
@@ -57,7 +57,7 @@
/// @param[out] pEndian return the endianness of the SPV module
///
/// @return result code
-spv_result_t spvBinaryEndianness(const spv_binary binary,
+spv_result_t spvBinaryEndianness(const spv_const_binary binary,
spv_endianness_t* pEndian);
#endif // LIBSPIRV_ENDIAN_H_
diff --git a/source/text.cpp b/source/text.cpp
old mode 100644
new mode 100755
index 48222b7..77da016
--- a/source/text.cpp
+++ b/source/text.cpp
@@ -737,7 +737,7 @@
} // anonymous namespace
spv_result_t spvTextToBinary(const char* input_text,
- const uint64_t input_text_size,
+ const size_t input_text_size,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable,
diff --git a/source/validate.cpp b/source/validate.cpp
old mode 100644
new mode 100755
index c8de619..3a142fa
--- a/source/validate.cpp
+++ b/source/validate.cpp
@@ -259,7 +259,7 @@
return SPV_SUCCESS;
}
-spv_result_t spvValidate(const spv_binary binary,
+spv_result_t spvValidate(const spv_const_binary binary,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable,
diff --git a/test/BinaryEndianness.cpp b/test/BinaryEndianness.cpp
old mode 100644
new mode 100755
index 484f248..480f652
--- a/test/BinaryEndianness.cpp
+++ b/test/BinaryEndianness.cpp
@@ -30,7 +30,7 @@
TEST(BinaryEndianness, InvalidCode) {
uint32_t invalidMagicNumber[] = {0};
- spv_binary_t binary = {invalidMagicNumber, 1};
+ spv_const_binary_t binary = {invalidMagicNumber, 1};
spv_endianness_t endian;
ASSERT_EQ(SPV_ERROR_INVALID_BINARY, spvBinaryEndianness(&binary, &endian));
}
@@ -42,7 +42,7 @@
} else {
magicNumber = 0x03022307;
}
- spv_binary_t binary = {&magicNumber, 1};
+ spv_const_binary_t binary = {&magicNumber, 1};
spv_endianness_t endian;
ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
ASSERT_EQ(SPV_ENDIANNESS_LITTLE, endian);
@@ -55,7 +55,7 @@
} else {
magicNumber = 0x03022307;
}
- spv_binary_t binary = {&magicNumber, 1};
+ spv_const_binary_t binary = {&magicNumber, 1};
spv_endianness_t endian;
ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
ASSERT_EQ(SPV_ENDIANNESS_BIG, endian);
diff --git a/test/BinaryHeaderGet.cpp b/test/BinaryHeaderGet.cpp
old mode 100644
new mode 100755
index 0d7bec0..853912b
--- a/test/BinaryHeaderGet.cpp
+++ b/test/BinaryHeaderGet.cpp
@@ -43,7 +43,9 @@
binary.code = code;
binary.wordCount = 6;
}
-
+ spv_const_binary_t get_const_binary() {
+ return spv_const_binary_t{binary.code, binary.wordCount};
+ }
virtual void TearDown() {}
uint32_t code[6];
@@ -52,10 +54,11 @@
TEST_F(BinaryHeaderGet, Default) {
spv_endianness_t endian;
- ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
+ spv_const_binary_t const_bin = get_const_binary();
+ ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&const_bin, &endian));
spv_header_t header;
- ASSERT_EQ(SPV_SUCCESS, spvBinaryHeaderGet(&binary, endian, &header));
+ ASSERT_EQ(SPV_SUCCESS, spvBinaryHeaderGet(&const_bin, endian, &header));
ASSERT_EQ(static_cast<uint32_t>(SpvMagicNumber), header.magic);
ASSERT_EQ(99u, header.version);
@@ -66,22 +69,24 @@
}
TEST_F(BinaryHeaderGet, InvalidCode) {
- spv_binary_t binary = {nullptr, 0};
+ spv_const_binary_t binary = {nullptr, 0};
spv_header_t header;
ASSERT_EQ(SPV_ERROR_INVALID_BINARY,
spvBinaryHeaderGet(&binary, SPV_ENDIANNESS_LITTLE, &header));
}
TEST_F(BinaryHeaderGet, InvalidPointerHeader) {
+ spv_const_binary_t const_bin = get_const_binary();
ASSERT_EQ(SPV_ERROR_INVALID_POINTER,
- spvBinaryHeaderGet(&binary, SPV_ENDIANNESS_LITTLE, nullptr));
+ spvBinaryHeaderGet(&const_bin, SPV_ENDIANNESS_LITTLE, nullptr));
}
TEST_F(BinaryHeaderGet, TruncatedHeader) {
for (int i = 1; i < SPV_INDEX_INSTRUCTION; i++) {
binary.wordCount = i;
+ spv_const_binary_t const_bin = get_const_binary();
ASSERT_EQ(SPV_ERROR_INVALID_BINARY,
- spvBinaryHeaderGet(&binary, SPV_ENDIANNESS_LITTLE, nullptr));
+ spvBinaryHeaderGet(&const_bin, SPV_ENDIANNESS_LITTLE, nullptr));
}
}
diff --git a/test/HexFloat.cpp b/test/HexFloat.cpp
old mode 100644
new mode 100755
index ee3be89..b4e96d7
--- a/test/HexFloat.cpp
+++ b/test/HexFloat.cpp
@@ -24,6 +24,12 @@
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+#ifdef _MSC_VER
+// We define this so that we can use sscanf in the tests without
+// MSVC warning us all the time.
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
#include <cmath>
#include <cstdio>
#include <sstream>
diff --git a/test/Validate.cpp b/test/Validate.cpp
old mode 100644
new mode 100755
index 2072ffe..7d1a9ca
--- a/test/Validate.cpp
+++ b/test/Validate.cpp
@@ -39,6 +39,9 @@
}
virtual void TearDown() { spvBinaryDestroy(binary); }
+ spv_const_binary get_const_binary() {
+ return spv_const_binary(binary);
+ }
spv_binary binary;
spv_opcode_table opcodeTable;
@@ -63,7 +66,7 @@
spvTextToBinary(str, strlen(str), opcodeTable, operandTable,
extInstTable, &binary, &diagnostic));
ASSERT_EQ(SPV_SUCCESS,
- spvValidate(binary, opcodeTable, operandTable, extInstTable,
+ spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
SPV_VALIDATE_ALL, &diagnostic));
if (diagnostic) {
spvDiagnosticPrint(diagnostic);
@@ -88,7 +91,7 @@
spvTextToBinary(str, strlen(str), opcodeTable, operandTable,
extInstTable, &binary, &diagnostic));
ASSERT_EQ(SPV_ERROR_INVALID_ID,
- spvValidate(binary, opcodeTable, operandTable, extInstTable,
+ spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
SPV_VALIDATE_ALL, &diagnostic));
ASSERT_NE(nullptr, diagnostic);
spvDiagnosticPrint(diagnostic);
@@ -113,7 +116,7 @@
extInstTable, &binary, &diagnostic));
// TODO: Fix setting of bound in spvTextTo, then remove this!
ASSERT_EQ(SPV_ERROR_INVALID_ID,
- spvValidate(binary, opcodeTable, operandTable, extInstTable,
+ spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
SPV_VALIDATE_ALL, &diagnostic));
ASSERT_NE(nullptr, diagnostic);
spvDiagnosticPrint(diagnostic);
diff --git a/test/ValidateID.cpp b/test/ValidateID.cpp
old mode 100644
new mode 100755
index 9abd49f..17a963d
--- a/test/ValidateID.cpp
+++ b/test/ValidateID.cpp
@@ -45,7 +45,9 @@
}
virtual void TearDown() { spvBinaryDestroy(binary); }
-
+ spv_const_binary get_const_binary() {
+ return spv_const_binary(binary);
+ }
spv_opcode_table opcodeTable;
spv_operand_table operandTable;
spv_ext_inst_table extInstTable;
@@ -63,8 +65,8 @@
ASSERT_EQ(SPV_SUCCESS, error); \
} \
spv_result_t result = \
- spvValidate(binary, opcodeTable, operandTable, extInstTable, \
- SPV_VALIDATE_ID_BIT, &diagnostic); \
+ spvValidate(get_const_binary(), opcodeTable, operandTable, \
+ extInstTable, SPV_VALIDATE_ID_BIT, &diagnostic); \
if (SPV_SUCCESS != result) { \
spvDiagnosticPrint(diagnostic); \
spvDiagnosticDestroy(diagnostic); \
diff --git a/tools/val/val.cpp b/tools/val/val.cpp
old mode 100644
new mode 100755
index e369ceb..8edfa85
--- a/tools/val/val.cpp
+++ b/tools/val/val.cpp
@@ -96,7 +96,7 @@
return 1;
}
- spv_binary_t binary = {contents.data(), contents.size()};
+ spv_const_binary_t binary = {contents.data(), contents.size()};
spv_opcode_table opcodeTable;
spv_result_t error = spvOpcodeTableGet(&opcodeTable);