// 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); }
TEST_P(GeneratorStringTest, Sample) { auto words = CompileSuccessfully(""); EXPECT_EQ(2u, SPV_INDEX_GENERATOR_NUMBER); words[SPV_INDEX_GENERATOR_NUMBER] = SPV_GENERATOR_WORD(GetParam().generator, GetParam().misc); spv_text decoded_text = nullptr; EXPECT_THAT(spvBinaryToText(ScopedContext().context, words.data(), words.size(), SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text, &diagnostic), Eq(SPV_SUCCESS)); EXPECT_THAT(diagnostic, Eq(nullptr)); EXPECT_THAT(std::string(decoded_text->str), HasSubstr(GetParam().expected)); spvTextDestroy(decoded_text); }