mirror of
https://gitee.com/openharmony/third_party_spirv-tools
synced 2024-11-23 07:20:28 +00:00
Remove table parameters from API functions.
Opcode, operand, and external instruction tables are no longer passed in as parameters to spvTextToBinary(), spvBinaryToText(), and spvValidate().
This commit is contained in:
parent
ec691fba2a
commit
df920ecb71
@ -389,7 +389,6 @@ typedef struct spv_const_binary_t {
|
||||
const size_t wordCount;
|
||||
} spv_const_binary_t;
|
||||
|
||||
|
||||
typedef struct spv_text_t {
|
||||
const char* str;
|
||||
size_t length;
|
||||
@ -452,17 +451,11 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pTable);
|
||||
///
|
||||
/// @param[in] text input text
|
||||
/// @param[in] length of the input text
|
||||
/// @param[in] opcodeTable of specified Opcodes
|
||||
/// @param[in] operandTable of specified operands
|
||||
/// @param[in] extInstTable of specified extended instructions
|
||||
/// @param[out] pBinary the binary module
|
||||
/// @param[out] pDiagnostic contains diagnostic on failure
|
||||
///
|
||||
/// @return result code
|
||||
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,
|
||||
spv_binary* pBinary, spv_diagnostic* pDiagnostic);
|
||||
|
||||
/// @brief Free an allocated text stream
|
||||
@ -479,19 +472,13 @@ void spvTextDestroy(spv_text text);
|
||||
/// @param[in] binary the input binary
|
||||
/// @param[in] wordCount the number of input words
|
||||
/// @param[in] options bitfield of spv_binary_to_text_options_t values
|
||||
/// @param[in] opcodeTable table of specified Opcodes
|
||||
/// @param[in] operandTable table of specified operands
|
||||
/// @param[in] extInstTable of specified extended instructions
|
||||
/// @param[out] pText the textual form
|
||||
/// @param[out] pDiagnostic contains diagnostic on failure
|
||||
///
|
||||
/// @return result code
|
||||
spv_result_t spvBinaryToText(const uint32_t* binary, const size_t wordCount,
|
||||
const uint32_t options,
|
||||
const spv_opcode_table opcodeTable,
|
||||
const spv_operand_table operandTable,
|
||||
const spv_ext_inst_table extInstTable,
|
||||
spv_text* pText, spv_diagnostic* pDiagnostic);
|
||||
const uint32_t options, spv_text* pText,
|
||||
spv_diagnostic* pDiagnostic);
|
||||
|
||||
/// @brief Free a binary stream from memory.
|
||||
///
|
||||
@ -505,18 +492,12 @@ void spvBinaryDestroy(spv_binary binary);
|
||||
/// @brief Validate a SPIR-V binary for correctness
|
||||
///
|
||||
/// @param[in] binary the input binary stream
|
||||
/// @param[in] opcodeTable table of specified Opcodes
|
||||
/// @param[in] operandTable table of specified operands
|
||||
/// @param[in] extInstTable of specified extended instructions
|
||||
/// @param[in] options bitfield of spv_validation_options_t
|
||||
/// @param[out] pDiagnostic contains diagnostic on failure
|
||||
///
|
||||
/// @return result code
|
||||
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,
|
||||
const uint32_t options, spv_diagnostic* pDiagnostic);
|
||||
spv_result_t spvValidate(const spv_const_binary binary, const uint32_t options,
|
||||
spv_diagnostic* pDiagnostic);
|
||||
|
||||
// Diagnostic API
|
||||
|
||||
|
@ -346,16 +346,12 @@ spv_result_t DisassembleInstruction(
|
||||
} // anonymous namespace
|
||||
|
||||
spv_result_t spvBinaryToText(const uint32_t* code, const size_t wordCount,
|
||||
const uint32_t options,
|
||||
const spv_opcode_table opcode_table,
|
||||
const spv_operand_table operand_table,
|
||||
const spv_ext_inst_table ext_inst_table,
|
||||
spv_text* pText, spv_diagnostic* pDiagnostic) {
|
||||
const uint32_t options, spv_text* pText,
|
||||
spv_diagnostic* pDiagnostic) {
|
||||
// Invalid arguments return error codes, but don't necessarily generate
|
||||
// diagnostics. These are programmer errors, not user errors.
|
||||
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
|
||||
const libspirv::AssemblyGrammar grammar(operand_table, opcode_table,
|
||||
ext_inst_table);
|
||||
const libspirv::AssemblyGrammar grammar;
|
||||
if (!grammar.isValid()) return SPV_ERROR_INVALID_TABLE;
|
||||
|
||||
Disassembler disassembler(grammar, code, wordCount, options);
|
||||
|
@ -737,13 +737,10 @@ spv_result_t spvTextToBinaryInternal(const libspirv::AssemblyGrammar& grammar,
|
||||
} // anonymous namespace
|
||||
|
||||
spv_result_t spvTextToBinary(const char* input_text,
|
||||
const size_t input_text_size,
|
||||
const spv_opcode_table opcodeTable,
|
||||
const spv_operand_table operandTable,
|
||||
const spv_ext_inst_table extInstTable,
|
||||
spv_binary* pBinary, spv_diagnostic* pDiagnostic) {
|
||||
const size_t input_text_size, spv_binary* pBinary,
|
||||
spv_diagnostic* pDiagnostic) {
|
||||
spv_text_t text = {input_text, input_text_size};
|
||||
libspirv::AssemblyGrammar grammar(operandTable, opcodeTable, extInstTable);
|
||||
libspirv::AssemblyGrammar grammar;
|
||||
|
||||
spv_result_t result =
|
||||
spvTextToBinaryInternal(grammar, &text, pBinary, pDiagnostic);
|
||||
|
@ -259,13 +259,20 @@ spv_result_t spvValidateIDs(const spv_instruction_t* pInsts,
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
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,
|
||||
const uint32_t options, spv_diagnostic* pDiagnostic) {
|
||||
if (!opcodeTable || !operandTable) return SPV_ERROR_INVALID_TABLE;
|
||||
spv_result_t spvValidate(const spv_const_binary binary, const uint32_t options,
|
||||
spv_diagnostic* pDiagnostic) {
|
||||
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
|
||||
spv_opcode_table opcode_table = nullptr;
|
||||
spvOpcodeTableGet(&opcode_table);
|
||||
assert(opcode_table);
|
||||
|
||||
spv_operand_table operand_table = nullptr;
|
||||
spvOperandTableGet(&operand_table);
|
||||
assert(operand_table);
|
||||
|
||||
spv_ext_inst_table ext_inst_table = nullptr;
|
||||
spvExtInstTableGet(&ext_inst_table);
|
||||
assert(ext_inst_table);
|
||||
|
||||
spv_endianness_t endian;
|
||||
spv_position_t position = {};
|
||||
@ -298,7 +305,7 @@ spv_result_t spvValidate(const spv_const_binary binary,
|
||||
position.index = SPV_INDEX_INSTRUCTION;
|
||||
// TODO: Imcomplete implementation
|
||||
spvCheckReturn(spvValidateBasic(instructions.data(), instructions.size(),
|
||||
opcodeTable, operandTable, &position,
|
||||
opcode_table, operand_table, &position,
|
||||
pDiagnostic));
|
||||
}
|
||||
|
||||
@ -310,8 +317,8 @@ spv_result_t spvValidate(const spv_const_binary binary,
|
||||
if (spvIsInBitfield(SPV_VALIDATE_ID_BIT, options)) {
|
||||
position.index = SPV_INDEX_INSTRUCTION;
|
||||
spvCheckReturn(spvValidateIDs(instructions.data(), instructions.size(),
|
||||
header.bound, opcodeTable, operandTable,
|
||||
extInstTable, &position, pDiagnostic));
|
||||
header.bound, opcode_table, operand_table,
|
||||
ext_inst_table, &position, pDiagnostic));
|
||||
}
|
||||
|
||||
if (spvIsInBitfield(SPV_VALIDATE_RULES_BIT, options)) {
|
||||
|
@ -33,8 +33,7 @@ using spvtest::TextToBinaryTest;
|
||||
TEST_F(TextToBinaryTest, NotPlacingResultIDAtTheBeginning) {
|
||||
SetText("OpTypeMatrix %1 %2 1000");
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
ASSERT_NE(nullptr, diagnostic);
|
||||
EXPECT_STREQ(
|
||||
"Expected <result-id> at the beginning of an instruction, found "
|
||||
|
@ -44,8 +44,7 @@ TEST_F(BinaryDestroySomething, Default) {
|
||||
SetText("OpSource OpenCL 120");
|
||||
spv_binary my_binary = nullptr;
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &my_binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &my_binary, &diagnostic));
|
||||
ASSERT_NE(nullptr, my_binary);
|
||||
spvBinaryDestroy(my_binary);
|
||||
}
|
||||
|
@ -39,13 +39,7 @@ namespace {
|
||||
|
||||
class BinaryToText : public ::testing::Test {
|
||||
public:
|
||||
BinaryToText() : binary(), opcodeTable(nullptr), operandTable(nullptr) {}
|
||||
|
||||
virtual void SetUp() {
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
|
||||
const char* textStr = R"(
|
||||
OpSource OpenCL 12
|
||||
OpMemoryModel Physical64 OpenCL
|
||||
@ -70,8 +64,7 @@ class BinaryToText : public ::testing::Test {
|
||||
spv_text_t text = {textStr, strlen(textStr)};
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spv_result_t error =
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -84,24 +77,19 @@ class BinaryToText : public ::testing::Test {
|
||||
// Compiles the given assembly text, and saves it into 'binary'.
|
||||
void CompileSuccessfully(std::string text) {
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
EXPECT_EQ(SPV_SUCCESS, spvTextToBinary(text.c_str(), text.size(),
|
||||
opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
EXPECT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(text.c_str(), text.size(), &binary, &diagnostic));
|
||||
}
|
||||
|
||||
spv_binary binary;
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
};
|
||||
|
||||
TEST_F(BinaryToText, Default) {
|
||||
spv_text text = nullptr;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text,
|
||||
&diagnostic));
|
||||
printf("%s", text->str);
|
||||
spvTextDestroy(text);
|
||||
}
|
||||
@ -109,10 +97,9 @@ TEST_F(BinaryToText, Default) {
|
||||
TEST_F(BinaryToText, MissingModule) {
|
||||
spv_text text;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
EXPECT_EQ(
|
||||
SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(nullptr, 42, SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic));
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(nullptr, 42, SPV_BINARY_TO_TEXT_OPTION_NONE, &text,
|
||||
&diagnostic));
|
||||
EXPECT_THAT(diagnostic->error, Eq(std::string("Missing module.")));
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
@ -128,10 +115,10 @@ TEST_F(BinaryToText, TruncatedModule) {
|
||||
for (int length = 0; length < SPV_INDEX_INSTRUCTION; length++) {
|
||||
spv_text text = nullptr;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(binary->code, length,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic));
|
||||
EXPECT_EQ(
|
||||
SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(binary->code, length, SPV_BINARY_TO_TEXT_OPTION_NONE,
|
||||
&text, &diagnostic));
|
||||
ASSERT_NE(nullptr, diagnostic);
|
||||
std::stringstream expected;
|
||||
expected << "Module has incomplete header: only " << length
|
||||
@ -149,10 +136,10 @@ TEST_F(BinaryToText, InvalidMagicNumber) {
|
||||
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spv_text text;
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(damaged_binary.data(), damaged_binary.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic));
|
||||
EXPECT_EQ(
|
||||
SPV_ERROR_INVALID_BINARY,
|
||||
spvBinaryToText(damaged_binary.data(), damaged_binary.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, &diagnostic));
|
||||
ASSERT_NE(nullptr, diagnostic);
|
||||
std::stringstream expected;
|
||||
expected << "Invalid SPIR-V magic number '" << std::hex
|
||||
@ -161,32 +148,11 @@ TEST_F(BinaryToText, InvalidMagicNumber) {
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
}
|
||||
|
||||
TEST_F(BinaryToText, InvalidTable) {
|
||||
spv_text text;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvBinaryToText(binary->code, binary->wordCount, 0, nullptr,
|
||||
operandTable, extInstTable, &text, &diagnostic));
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
nullptr, extInstTable, &text, &diagnostic));
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, nullptr, &text, &diagnostic));
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(BinaryToText, InvalidDiagnostic) {
|
||||
spv_text text;
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_DIAGNOSTIC,
|
||||
spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, nullptr));
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, nullptr));
|
||||
}
|
||||
|
||||
struct FailedDecodeCase {
|
||||
@ -249,23 +215,15 @@ INSTANTIATE_TEST_CASE_P(
|
||||
|
||||
TEST(BinaryToTextSmall, OneInstruction) {
|
||||
// TODO(dneto): This test could/should be refactored.
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
const char* input = "OpSource OpenCL 12";
|
||||
spv_result_t error =
|
||||
spvTextToBinary(input, strlen(input), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(input, strlen(input), &binary, &diagnostic);
|
||||
ASSERT_EQ(SPV_SUCCESS, error);
|
||||
spv_text text = nullptr;
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic);
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, &diagnostic);
|
||||
EXPECT_EQ(SPV_SUCCESS, error);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
@ -278,12 +236,6 @@ TEST(BinaryToTextSmall, OneInstruction) {
|
||||
// This could detect problems in updating the expected-set-of-operands
|
||||
// list.
|
||||
TEST(BinaryToTextSmall, OperandWithOperands) {
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
|
||||
@ -293,14 +245,12 @@ TEST(BinaryToTextSmall, OperandWithOperands) {
|
||||
%fnType = OpTypeFunction %void
|
||||
%fn = OpFunction %void None %fnType
|
||||
)");
|
||||
spv_result_t error =
|
||||
spvTextToBinary(input.str.c_str(), input.str.length(), opcodeTable,
|
||||
operandTable, extInstTable, &binary, &diagnostic);
|
||||
spv_result_t error = spvTextToBinary(input.str.c_str(), input.str.length(),
|
||||
&binary, &diagnostic);
|
||||
ASSERT_EQ(SPV_SUCCESS, error);
|
||||
spv_text text = nullptr;
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic);
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, &diagnostic);
|
||||
EXPECT_EQ(SPV_SUCCESS, error);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
@ -310,24 +260,16 @@ TEST(BinaryToTextSmall, OperandWithOperands) {
|
||||
}
|
||||
|
||||
TEST(BinaryToTextSmall, LiteralInt64) {
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
|
||||
AutoText input("%1 = OpTypeInt 64 0\n%2 = OpConstant %1 123456789021\n");
|
||||
spv_result_t error =
|
||||
spvTextToBinary(input.str.c_str(), input.str.length(), opcodeTable,
|
||||
operandTable, extInstTable, &binary, &diagnostic);
|
||||
spv_result_t error = spvTextToBinary(input.str.c_str(), input.str.length(),
|
||||
&binary, &diagnostic);
|
||||
ASSERT_EQ(SPV_SUCCESS, error);
|
||||
spv_text text = nullptr;
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic);
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -341,25 +283,17 @@ TEST(BinaryToTextSmall, LiteralInt64) {
|
||||
}
|
||||
|
||||
TEST(BinaryToTextSmall, LiteralDouble) {
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
|
||||
AutoText input(
|
||||
"%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 3.1415926535897930");
|
||||
spv_result_t error =
|
||||
spvTextToBinary(input.str.c_str(), input.str.length(), opcodeTable,
|
||||
operandTable, extInstTable, &binary, &diagnostic);
|
||||
spv_result_t error = spvTextToBinary(input.str.c_str(), input.str.length(),
|
||||
&binary, &diagnostic);
|
||||
ASSERT_EQ(SPV_SUCCESS, error);
|
||||
spv_text text = nullptr;
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &text, &diagnostic);
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &text, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
@ -49,13 +49,6 @@ struct ExtInstContext {
|
||||
using ExtInstGLSLstd450RoundTripTest = ::testing::TestWithParam<ExtInstContext>;
|
||||
|
||||
TEST_P(ExtInstGLSLstd450RoundTripTest, ParameterizedExtInst) {
|
||||
spv_opcode_table opcodeTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
spv_operand_table operandTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
|
||||
const std::string spirv = R"(
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
@ -79,8 +72,7 @@ OpFunctionEnd
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic;
|
||||
spv_result_t error =
|
||||
spvTextToBinary(spirv.c_str(), spirv.size(), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(spirv.c_str(), spirv.size(), &binary, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -106,9 +98,9 @@ OpFunctionEnd
|
||||
|
||||
// Check round trip gives the same text.
|
||||
spv_text output_text = nullptr;
|
||||
error = spvBinaryToText(
|
||||
binary->code, binary->wordCount, SPV_BINARY_TO_TEXT_OPTION_NONE,
|
||||
opcodeTable, operandTable, extInstTable, &output_text, &diagnostic);
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &output_text,
|
||||
&diagnostic);
|
||||
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
|
@ -47,8 +47,7 @@ using ::testing::StrEq;
|
||||
TEST_F(TextToBinaryTest, ImmediateIntOpCode) {
|
||||
SetText("!0x00FF00FF");
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(0x00FF00FF, binary->code[5]);
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
@ -58,8 +57,7 @@ TEST_F(TextToBinaryTest, ImmediateIntOpCode) {
|
||||
TEST_F(TextToBinaryTest, ImmediateIntOperand) {
|
||||
SetText("OpCapability !0x00FF00FF");
|
||||
EXPECT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(0x00FF00FF, binary->code[6]);
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
|
@ -45,17 +45,10 @@ TEST(NamedId, Default) {
|
||||
spv_text_t text;
|
||||
text.str = spirv;
|
||||
text.length = strlen(spirv);
|
||||
spv_opcode_table opcodeTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
spv_operand_table operandTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
spv_binary binary = nullptr;
|
||||
spv_diagnostic diagnostic;
|
||||
spv_result_t error =
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -65,7 +58,7 @@ TEST(NamedId, Default) {
|
||||
error = spvBinaryToText(
|
||||
binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_PRINT | SPV_BINARY_TO_TEXT_OPTION_COLOR,
|
||||
opcodeTable, operandTable, extInstTable, nullptr, &diagnostic);
|
||||
nullptr, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
@ -42,15 +42,7 @@ class TextToBinaryTestBase : public T {
|
||||
// Offset into a SpirvVector at which the first instruction starts.
|
||||
const SpirvVector::size_type kFirstInstruction = 5;
|
||||
|
||||
TextToBinaryTestBase()
|
||||
: opcodeTable(nullptr),
|
||||
operandTable(nullptr),
|
||||
diagnostic(nullptr),
|
||||
text(),
|
||||
binary(nullptr) {
|
||||
EXPECT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
EXPECT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
EXPECT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
TextToBinaryTestBase() : diagnostic(nullptr), text(), binary(nullptr) {
|
||||
char textStr[] = "substitute the text member variable with your test";
|
||||
text = {textStr, strlen(textStr)};
|
||||
}
|
||||
@ -70,8 +62,7 @@ class TextToBinaryTestBase : public T {
|
||||
// compilation success. Returns the compiled code.
|
||||
SpirvVector CompileSuccessfully(const std::string& text) {
|
||||
spv_result_t status =
|
||||
spvTextToBinary(text.c_str(), text.size(), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(text.c_str(), text.size(), &binary, &diagnostic);
|
||||
EXPECT_EQ(SPV_SUCCESS, status) << text;
|
||||
SpirvVector code_copy;
|
||||
if (status == SPV_SUCCESS) {
|
||||
@ -87,8 +78,7 @@ class TextToBinaryTestBase : public T {
|
||||
// Returns the error message(s).
|
||||
std::string CompileFailure(const std::string& text) {
|
||||
EXPECT_NE(SPV_SUCCESS,
|
||||
spvTextToBinary(text.c_str(), text.size(), opcodeTable,
|
||||
operandTable, extInstTable, &binary, &diagnostic))
|
||||
spvTextToBinary(text.c_str(), text.size(), &binary, &diagnostic))
|
||||
<< text;
|
||||
DestroyBinary();
|
||||
return diagnostic->error;
|
||||
@ -99,8 +89,7 @@ class TextToBinaryTestBase : public T {
|
||||
std::string EncodeAndDecodeSuccessfully(const std::string& text) {
|
||||
DestroyBinary();
|
||||
spv_result_t error =
|
||||
spvTextToBinary(text.c_str(), text.size(), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(text.c_str(), text.size(), &binary, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -109,9 +98,9 @@ class TextToBinaryTestBase : public T {
|
||||
if (!binary) return "";
|
||||
|
||||
spv_text decoded_text;
|
||||
error = spvBinaryToText(
|
||||
binary->code, binary->wordCount, SPV_BINARY_TO_TEXT_OPTION_NONE,
|
||||
opcodeTable, operandTable, extInstTable, &decoded_text, &diagnostic);
|
||||
error = spvBinaryToText(binary->code, binary->wordCount,
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text,
|
||||
&diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -137,11 +126,9 @@ class TextToBinaryTestBase : public T {
|
||||
spvtest::Concatenate({CompileSuccessfully(text), words_to_append});
|
||||
|
||||
spv_text decoded_text;
|
||||
EXPECT_NE(SPV_SUCCESS,
|
||||
spvBinaryToText(code.data(), code.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
|
||||
operandTable, extInstTable, &decoded_text,
|
||||
&diagnostic));
|
||||
EXPECT_NE(SPV_SUCCESS, spvBinaryToText(code.data(), code.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE,
|
||||
&decoded_text, &diagnostic));
|
||||
if (diagnostic) {
|
||||
std::string error_message = diagnostic->error;
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -176,9 +163,6 @@ class TextToBinaryTestBase : public T {
|
||||
binary = nullptr;
|
||||
}
|
||||
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
spv_diagnostic diagnostic;
|
||||
|
||||
std::string textString;
|
||||
|
@ -31,15 +31,6 @@ namespace {
|
||||
TEST(TextDestroy, DestroyNull) { spvBinaryDestroy(nullptr); }
|
||||
|
||||
TEST(TextDestroy, Default) {
|
||||
spv_opcode_table opcodeTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
|
||||
spv_operand_table operandTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
|
||||
char textStr[] = R"(
|
||||
OpSource OpenCL 12
|
||||
OpMemoryModel Physical64 OpenCL
|
||||
@ -65,8 +56,7 @@ TEST(TextDestroy, Default) {
|
||||
spv_binary binary = nullptr;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
EXPECT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(textStr, strlen(textStr), &binary, &diagnostic));
|
||||
EXPECT_NE(nullptr, binary);
|
||||
EXPECT_NE(nullptr, binary->code);
|
||||
EXPECT_NE(0, binary->wordCount);
|
||||
@ -76,10 +66,8 @@ TEST(TextDestroy, Default) {
|
||||
}
|
||||
|
||||
spv_text resultText = nullptr;
|
||||
EXPECT_EQ(
|
||||
SPV_SUCCESS,
|
||||
spvBinaryToText(binary->code, binary->wordCount, 0, opcodeTable,
|
||||
operandTable, extInstTable, &resultText, &diagnostic));
|
||||
EXPECT_EQ(SPV_SUCCESS, spvBinaryToText(binary->code, binary->wordCount, 0,
|
||||
&resultText, &diagnostic));
|
||||
spvBinaryDestroy(binary);
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
|
@ -164,20 +164,10 @@ TEST(TextToBinary, Default) {
|
||||
%15 = OpTypeVector %4 2
|
||||
)";
|
||||
|
||||
spv_opcode_table opcodeTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
|
||||
spv_operand_table operandTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
|
||||
spv_ext_inst_table extInstTable;
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spv_result_t error =
|
||||
spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic);
|
||||
spvTextToBinary(textStr, strlen(textStr), &binary, &diagnostic);
|
||||
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
@ -304,32 +294,16 @@ TEST(TextToBinary, Default) {
|
||||
TEST_F(TextToBinaryTest, InvalidText) {
|
||||
spv_binary binary;
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(nullptr, 0, opcodeTable, operandTable, extInstTable,
|
||||
&binary, &diagnostic));
|
||||
spvTextToBinary(nullptr, 0, &binary, &diagnostic));
|
||||
EXPECT_NE(nullptr, diagnostic);
|
||||
EXPECT_THAT(diagnostic->error, Eq(std::string("Missing assembly text.")));
|
||||
}
|
||||
|
||||
TEST_F(TextToBinaryTest, InvalidTable) {
|
||||
SetText(
|
||||
"OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvTextToBinary(text.str, text.length, nullptr, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, nullptr,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TABLE,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
nullptr, &binary, &diagnostic));
|
||||
}
|
||||
|
||||
TEST_F(TextToBinaryTest, InvalidPointer) {
|
||||
SetText(
|
||||
"OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_POINTER,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, nullptr, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, nullptr, &diagnostic));
|
||||
}
|
||||
|
||||
TEST_F(TextToBinaryTest, InvalidDiagnostic) {
|
||||
@ -337,15 +311,13 @@ TEST_F(TextToBinaryTest, InvalidDiagnostic) {
|
||||
"OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
|
||||
spv_binary binary;
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_DIAGNOSTIC,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, nullptr));
|
||||
spvTextToBinary(text.str, text.length, &binary, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(TextToBinaryTest, InvalidPrefix) {
|
||||
SetText("Invalid");
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
}
|
||||
@ -360,8 +332,7 @@ TEST_F(TextToBinaryTest, EmptyAssemblyString) {
|
||||
TEST_F(TextToBinaryTest, StringSpace) {
|
||||
SetText("OpSourceExtension \"string with spaces\"");
|
||||
EXPECT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
}
|
||||
@ -375,8 +346,7 @@ Google
|
||||
)");
|
||||
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(4, diagnostic->position.line + 1);
|
||||
EXPECT_EQ(1, diagnostic->position.column + 1);
|
||||
EXPECT_STREQ(
|
||||
@ -393,8 +363,7 @@ TEST_F(TextToBinaryTest, NoEqualSign) {
|
||||
)");
|
||||
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(5, diagnostic->position.line + 1);
|
||||
EXPECT_EQ(1, diagnostic->position.column + 1);
|
||||
EXPECT_STREQ("Expected '=', found end of stream.", diagnostic->error);
|
||||
@ -408,8 +377,7 @@ TEST_F(TextToBinaryTest, NoOpCode) {
|
||||
)");
|
||||
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(5, diagnostic->position.line + 1);
|
||||
EXPECT_EQ(1, diagnostic->position.column + 1);
|
||||
EXPECT_STREQ("Expected opcode, found end of stream.", diagnostic->error);
|
||||
@ -423,8 +391,7 @@ TEST_F(TextToBinaryTest, WrongOpCode) {
|
||||
)");
|
||||
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
|
||||
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(text.str, text.length, &binary, &diagnostic));
|
||||
EXPECT_EQ(4, diagnostic->position.line + 1);
|
||||
EXPECT_EQ(6, diagnostic->position.column + 1);
|
||||
EXPECT_STREQ("Invalid Opcode prefix 'Wahahaha'.", diagnostic->error);
|
||||
|
@ -30,23 +30,12 @@ namespace {
|
||||
|
||||
class Validate : public ::testing::Test {
|
||||
public:
|
||||
Validate() : binary(), opcodeTable(nullptr), operandTable(nullptr) {}
|
||||
|
||||
virtual void SetUp() {
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
}
|
||||
Validate() : binary() {}
|
||||
|
||||
virtual void TearDown() { spvBinaryDestroy(binary); }
|
||||
spv_const_binary get_const_binary() {
|
||||
return spv_const_binary(binary);
|
||||
}
|
||||
spv_const_binary get_const_binary() { return spv_const_binary(binary); }
|
||||
|
||||
spv_binary binary;
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_operand_table operandTable;
|
||||
spv_ext_inst_table extInstTable;
|
||||
};
|
||||
|
||||
TEST_F(Validate, DISABLED_Default) {
|
||||
@ -63,11 +52,9 @@ OpFunctionEnd
|
||||
)";
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(str, strlen(str), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(str, strlen(str), &binary, &diagnostic));
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
|
||||
SPV_VALIDATE_ALL, &diagnostic));
|
||||
spvValidate(get_const_binary(), SPV_VALIDATE_ALL, &diagnostic));
|
||||
if (diagnostic) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -88,11 +75,9 @@ OpFunctionEnd
|
||||
)";
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(str, strlen(str), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(str, strlen(str), &binary, &diagnostic));
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_ID,
|
||||
spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
|
||||
SPV_VALIDATE_ALL, &diagnostic));
|
||||
spvValidate(get_const_binary(), SPV_VALIDATE_ALL, &diagnostic));
|
||||
ASSERT_NE(nullptr, diagnostic);
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
@ -112,12 +97,10 @@ OpFunctionEnd
|
||||
)";
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
ASSERT_EQ(SPV_SUCCESS,
|
||||
spvTextToBinary(str, strlen(str), opcodeTable, operandTable,
|
||||
extInstTable, &binary, &diagnostic));
|
||||
spvTextToBinary(str, strlen(str), &binary, &diagnostic));
|
||||
// TODO: Fix setting of bound in spvTextTo, then remove this!
|
||||
ASSERT_EQ(SPV_ERROR_INVALID_ID,
|
||||
spvValidate(get_const_binary(), opcodeTable, operandTable, extInstTable,
|
||||
SPV_VALIDATE_ALL, &diagnostic));
|
||||
spvValidate(get_const_binary(), SPV_VALIDATE_ALL, &diagnostic));
|
||||
ASSERT_NE(nullptr, diagnostic);
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
@ -36,41 +36,26 @@ namespace {
|
||||
|
||||
class ValidateID : public ::testing::Test {
|
||||
public:
|
||||
ValidateID() : opcodeTable(nullptr), operandTable(nullptr), binary() {}
|
||||
|
||||
virtual void SetUp() {
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
|
||||
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
|
||||
}
|
||||
|
||||
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;
|
||||
spv_const_binary get_const_binary() { return spv_const_binary(binary); }
|
||||
spv_binary binary;
|
||||
};
|
||||
|
||||
#define CHECK(str, expected) \
|
||||
spv_diagnostic diagnostic; \
|
||||
spv_result_t error = \
|
||||
spvTextToBinary(str, strlen(str), opcodeTable, operandTable, \
|
||||
extInstTable, &binary, &diagnostic); \
|
||||
if (error) { \
|
||||
spvDiagnosticPrint(diagnostic); \
|
||||
spvDiagnosticDestroy(diagnostic); \
|
||||
ASSERT_EQ(SPV_SUCCESS, error); \
|
||||
} \
|
||||
spv_result_t result = \
|
||||
spvValidate(get_const_binary(), opcodeTable, operandTable, \
|
||||
extInstTable, SPV_VALIDATE_ID_BIT, &diagnostic); \
|
||||
if (SPV_SUCCESS != result) { \
|
||||
spvDiagnosticPrint(diagnostic); \
|
||||
spvDiagnosticDestroy(diagnostic); \
|
||||
} \
|
||||
#define CHECK(str, expected) \
|
||||
spv_diagnostic diagnostic; \
|
||||
spv_result_t error = \
|
||||
spvTextToBinary(str, strlen(str), &binary, &diagnostic); \
|
||||
if (error) { \
|
||||
spvDiagnosticPrint(diagnostic); \
|
||||
spvDiagnosticDestroy(diagnostic); \
|
||||
ASSERT_EQ(SPV_SUCCESS, error); \
|
||||
} \
|
||||
spv_result_t result = \
|
||||
spvValidate(get_const_binary(), SPV_VALIDATE_ID_BIT, &diagnostic); \
|
||||
if (SPV_SUCCESS != result) { \
|
||||
spvDiagnosticPrint(diagnostic); \
|
||||
spvDiagnosticDestroy(diagnostic); \
|
||||
} \
|
||||
ASSERT_EQ(expected, result);
|
||||
|
||||
// TODO: OpUndef
|
||||
|
@ -91,28 +91,10 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_result_t error = spvOpcodeTableGet(&opcodeTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_operand_table operandTable;
|
||||
error = spvOperandTableGet(&operandTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_ext_inst_table extInstTable;
|
||||
error = spvExtInstTableGet(&extInstTable);
|
||||
if (error) fprintf(stderr, "error: Internal malfunction.\n");
|
||||
|
||||
spv_binary binary;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
error = spvTextToBinary(contents.data(), contents.size(), opcodeTable,
|
||||
operandTable, extInstTable, &binary, &diagnostic);
|
||||
spv_result_t error =
|
||||
spvTextToBinary(contents.data(), contents.size(), &binary, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
@ -101,24 +101,6 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_result_t error = spvOpcodeTableGet(&opcodeTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_operand_table operandTable;
|
||||
error = spvOperandTableGet(&operandTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_ext_inst_table extInstTable;
|
||||
error = spvExtInstTableGet(&extInstTable);
|
||||
if (error) fprintf(stderr, "error: Internal malfunction.\n");
|
||||
|
||||
// If the printing option is turned on, then spvBinaryToText should
|
||||
// do the printing. In particular, colour printing on Windows is
|
||||
// controlled by modifying console objects synchronously while
|
||||
@ -131,9 +113,8 @@ int main(int argc, char** argv) {
|
||||
spv_text text;
|
||||
spv_text* textOrNull = printOptionOn ? nullptr : &text;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
error =
|
||||
spvBinaryToText(contents.data(), contents.size(), options, opcodeTable,
|
||||
operandTable, extInstTable, textOrNull, &diagnostic);
|
||||
spv_result_t error = spvBinaryToText(contents.data(), contents.size(),
|
||||
options, textOrNull, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
@ -98,27 +98,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
spv_const_binary_t binary = {contents.data(), contents.size()};
|
||||
|
||||
spv_opcode_table opcodeTable;
|
||||
spv_result_t error = spvOpcodeTableGet(&opcodeTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_operand_table operandTable;
|
||||
error = spvOperandTableGet(&operandTable);
|
||||
if (error) {
|
||||
fprintf(stderr, "error: internal malfunction\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
spv_ext_inst_table extInstTable;
|
||||
error = spvExtInstTableGet(&extInstTable);
|
||||
if (error) fprintf(stderr, "error: Internal malfunction.\n");
|
||||
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
error = spvValidate(&binary, opcodeTable, operandTable, extInstTable, options,
|
||||
&diagnostic);
|
||||
spv_result_t error = spvValidate(&binary, options, &diagnostic);
|
||||
if (error) {
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
|
Loading…
Reference in New Issue
Block a user