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

This commit is contained in:
Lei Zhang 2015-08-24 15:52:26 -04:00 committed by David Neto
parent 31e482cdf5
commit 8a37520908
2 changed files with 22 additions and 15 deletions

View File

@ -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;
}

View File

@ -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);