spirv-reader: Add a disassembler helper
This helped me debug a problem. Change-Id: I665aaa482c6f20d24966f0990bfe4e15cdd82915 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33800 Commit-Queue: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Auto-Submit: David Neto <dneto@google.com>
This commit is contained in:
parent
1e87fe5517
commit
1b543c6778
|
@ -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<uint32_t> 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<uint32_t>& 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
|
||||
|
|
|
@ -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<uint32_t> 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<uint32_t>& spirv_module);
|
||||
|
||||
} // namespace test
|
||||
} // namespace spirv
|
||||
} // namespace reader
|
||||
|
|
Loading…
Reference in New Issue