From 8a37520908e9e64b8a07cdd9e27dd3d81eb08bdc Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 24 Aug 2015 15:52:26 -0400 Subject: [PATCH] Disassemble in the format of " = ..". --- source/binary.cpp | 13 ++++++++++--- test/BinaryToText.cpp | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index fe48aa93..69eb816f 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -348,7 +348,10 @@ spv_result_t spvBinaryDecodeOpcode( << "'."; return SPV_ERROR_INVALID_BINARY); - stream.get() << "Op" << opcodeEntry->name; + std::stringstream no_result_id_strstream; + out_stream no_result_id_stream(no_result_id_strstream); + const int16_t result_id_index = spvOpcodeResultIdIndex(opcodeEntry); + no_result_id_stream.get() << "Op" << opcodeEntry->name; position->index++; @@ -357,17 +360,21 @@ spv_result_t spvBinaryDecodeOpcode( const uint32_t word = spvFixWord(pInst->words[index], endian); const uint64_t currentPosIndex = position->index; - stream.get() << " "; + if (result_id_index != index - 1) no_result_id_strstream << " "; spv_operand_type_t type = spvBinaryOperandInfo(word, index, opcodeEntry, operandTable, &operandEntry); spvCheck(spvBinaryDecodeOperand( opcodeEntry->opcode, type, pInst->words + index, endian, options, operandTable, extInstTable, &pInst->extInstType, - stream, position, pDiagnostic), + (result_id_index == index - 1 ? stream : no_result_id_stream), + position, pDiagnostic), return SPV_ERROR_INVALID_BINARY); + if (result_id_index == index - 1) stream.get() << " = "; index += (uint16_t)(position->index - currentPosIndex - 1); } + stream.get() << no_result_id_strstream.str(); + return SPV_SUCCESS; } diff --git a/test/BinaryToText.cpp b/test/BinaryToText.cpp index 702a64e5..120f21aa 100644 --- a/test/BinaryToText.cpp +++ b/test/BinaryToText.cpp @@ -35,7 +35,7 @@ class BinaryToText : public ::testing::Test { ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable)); ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable)); - const char *textStr = R"( + const char* textStr = R"( OpSource OpenCL 12 OpMemoryModel Physical64 OpenCL OpSourceExtension "PlaceholderExtensionName" @@ -141,16 +141,16 @@ TEST_P(BinaryToTextGLExtSingleFloatInst, Default) { ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable)); const std::string spirv = R"( OpCapability Shader -OpExtInstImport %1 "GLSL.std.450" +%1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical Simple OpEntryPoint Vertex %2 "main" -OpTypeVoid %3 -OpTypeFloat %4 32 -OpConstant %4 %5 1 -OpTypeFunction %6 %3 -OpFunction %3 %2 None %6 -OpLabel %8 -OpExtInst %4 %9 %1 )" + std::string(GetParam().inst) + +%3 = OpTypeVoid +%4 = OpTypeFloat 32 +%5 = OpConstant %4 1 +%6 = OpTypeFunction %3 +%2 = OpFunction %3 None %6 +%8 = OpLabel +%9 = OpExtInst %4 %1 )" + std::string(GetParam().inst) + R"( %5 OpReturn OpFunctionEnd @@ -176,9 +176,9 @@ OpFunctionEnd } spv_text output_text; - error = spvBinaryToText( - binary, SPV_BINARY_TO_TEXT_OPTION_NONE, - opcodeTable, operandTable, extInstTable, &output_text, &diagnostic); + error = + spvBinaryToText(binary, SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable, + operandTable, extInstTable, &output_text, &diagnostic); if (error) { spvDiagnosticPrint(diagnostic);