diff --git a/src/reader/spirv/spirv_tools_helpers_test.cc b/src/reader/spirv/spirv_tools_helpers_test.cc index 81dd5e7232..4849a7a3a7 100644 --- a/src/reader/spirv/spirv_tools_helpers_test.cc +++ b/src/reader/spirv/spirv_tools_helpers_test.cc @@ -26,8 +26,6 @@ namespace reader { namespace spirv { namespace test { -/// @returns the SPIR-V module assembled from the given text. Numeric IDs -/// are preserved. std::vector Assemble(const std::string& spirv_assembly) { // TODO(dneto): Use ScopedTrace? @@ -69,6 +67,23 @@ std::string AssembleFailure(const std::string& spirv_assembly) { return errors.str(); } +std::string Disassemble(const std::vector& spirv_module) { + spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_0); + std::stringstream errors; + tools.SetMessageConsumer([&errors](spv_message_level_t, const char*, + const spv_position_t& position, + const char* message) { + errors << "disassmbly error:" << position.line << ":" << position.column + << ": " << message; + }); + + std::string result; + const auto success = tools.Disassemble(spirv_module, &result); + EXPECT_TRUE(success) << errors.str(); + + return result; +} + } // namespace test } // namespace spirv } // namespace reader diff --git a/src/reader/spirv/spirv_tools_helpers_test.h b/src/reader/spirv/spirv_tools_helpers_test.h index ba4ad6863f..654d85a936 100644 --- a/src/reader/spirv/spirv_tools_helpers_test.h +++ b/src/reader/spirv/spirv_tools_helpers_test.h @@ -24,14 +24,20 @@ namespace reader { namespace spirv { namespace test { +/// @param spirv_assembly SPIR-V assembly text /// @returns the SPIR-V module assembled from the given text. Numeric IDs /// are preserved. std::vector Assemble(const std::string& spirv_assembly); /// Attempts to assemble given SPIR-V assembly text. Expect it to fail. +/// @param spirv_assembly the SPIR-V assembly /// @returns the failure message. std::string AssembleFailure(const std::string& spirv_assembly); +/// @param spirv_module a SPIR-V binary module +/// @returns the disassembled module +std::string Disassemble(const std::vector& spirv_module); + } // namespace test } // namespace spirv } // namespace reader