Disassemble in the format of "<result-id> = <opcode> <operand>..".

This commit is contained in:
Lei Zhang 2015-08-24 15:52:26 -04:00 коммит произвёл David Neto
Родитель 31e482cdf5
Коммит 8a37520908
2 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -348,7 +348,10 @@ spv_result_t spvBinaryDecodeOpcode(
<< "'."; << "'.";
return SPV_ERROR_INVALID_BINARY); 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++; position->index++;
@ -357,17 +360,21 @@ spv_result_t spvBinaryDecodeOpcode(
const uint32_t word = spvFixWord(pInst->words[index], endian); const uint32_t word = spvFixWord(pInst->words[index], endian);
const uint64_t currentPosIndex = position->index; 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, spv_operand_type_t type = spvBinaryOperandInfo(word, index, opcodeEntry,
operandTable, &operandEntry); operandTable, &operandEntry);
spvCheck(spvBinaryDecodeOperand( spvCheck(spvBinaryDecodeOperand(
opcodeEntry->opcode, type, pInst->words + index, endian, opcodeEntry->opcode, type, pInst->words + index, endian,
options, operandTable, extInstTable, &pInst->extInstType, 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); return SPV_ERROR_INVALID_BINARY);
if (result_id_index == index - 1) stream.get() << " = ";
index += (uint16_t)(position->index - currentPosIndex - 1); index += (uint16_t)(position->index - currentPosIndex - 1);
} }
stream.get() << no_result_id_strstream.str();
return SPV_SUCCESS; return SPV_SUCCESS;
} }

Просмотреть файл

@ -35,7 +35,7 @@ class BinaryToText : public ::testing::Test {
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable)); ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&operandTable));
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable)); ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
const char *textStr = R"( const char* textStr = R"(
OpSource OpenCL 12 OpSource OpenCL 12
OpMemoryModel Physical64 OpenCL OpMemoryModel Physical64 OpenCL
OpSourceExtension "PlaceholderExtensionName" OpSourceExtension "PlaceholderExtensionName"
@ -141,16 +141,16 @@ TEST_P(BinaryToTextGLExtSingleFloatInst, Default) {
ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable)); ASSERT_EQ(SPV_SUCCESS, spvExtInstTableGet(&extInstTable));
const std::string spirv = R"( const std::string spirv = R"(
OpCapability Shader OpCapability Shader
OpExtInstImport %1 "GLSL.std.450" %1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint Vertex %2 "main" OpEntryPoint Vertex %2 "main"
OpTypeVoid %3 %3 = OpTypeVoid
OpTypeFloat %4 32 %4 = OpTypeFloat 32
OpConstant %4 %5 1 %5 = OpConstant %4 1
OpTypeFunction %6 %3 %6 = OpTypeFunction %3
OpFunction %3 %2 None %6 %2 = OpFunction %3 None %6
OpLabel %8 %8 = OpLabel
OpExtInst %4 %9 %1 )" + std::string(GetParam().inst) + %9 = OpExtInst %4 %1 )" + std::string(GetParam().inst) +
R"( %5 R"( %5
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
@ -176,9 +176,9 @@ OpFunctionEnd
} }
spv_text output_text; spv_text output_text;
error = spvBinaryToText( error =
binary, SPV_BINARY_TO_TEXT_OPTION_NONE, spvBinaryToText(binary, SPV_BINARY_TO_TEXT_OPTION_NONE, opcodeTable,
opcodeTable, operandTable, extInstTable, &output_text, &diagnostic); operandTable, extInstTable, &output_text, &diagnostic);
if (error) { if (error) {
spvDiagnosticPrint(diagnostic); spvDiagnosticPrint(diagnostic);