SPV: Add option to print disassembly in standard form using SPIRV-Tools.
This commit is contained in:
@@ -60,6 +60,7 @@ if(ENABLE_OPT)
|
||||
PRIVATE ${spirv-tools_SOURCE_DIR}/source
|
||||
)
|
||||
target_link_libraries(SPIRV glslang SPIRV-Tools-opt)
|
||||
target_include_directories(SPIRV PUBLIC ../External)
|
||||
else()
|
||||
target_link_libraries(SPIRV glslang)
|
||||
endif(ENABLE_OPT)
|
||||
|
||||
@@ -716,4 +716,25 @@ void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
|
||||
SpirvStream.processInstructions();
|
||||
}
|
||||
|
||||
#if ENABLE_OPT
|
||||
|
||||
#include "spirv-tools/source/disassemble.h"
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
|
||||
{
|
||||
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
|
||||
spv_text text;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spvBinaryToText(context, &spirv.front(), spirv.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT,
|
||||
&text, &diagnostic);
|
||||
if (diagnostic == nullptr)
|
||||
out << text->str;
|
||||
else
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}; // end namespace spv
|
||||
|
||||
@@ -45,8 +45,12 @@
|
||||
|
||||
namespace spv {
|
||||
|
||||
// disassemble with glslang custom disassembler
|
||||
void Disassemble(std::ostream& out, const std::vector<unsigned int>&);
|
||||
|
||||
// disassemble with SPIRV-Tools disassembler
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& stream);
|
||||
|
||||
}; // end namespace spv
|
||||
|
||||
#endif // disassembler_H
|
||||
|
||||
Reference in New Issue
Block a user