Commit 2fecfc5b by Ben Clayton

SpirvShaderDebugger: Add string helper for debug kinds

Makes for easier reading of the assertion macros. Bug: b/148401179 Change-Id: Icc48baa9c476967c6dea19c2f0e91ed253dce323 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42194Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent da38401b
...@@ -134,6 +134,32 @@ struct Object ...@@ -134,6 +134,32 @@ struct Object
static constexpr bool kindof(Object::Kind kind) { return true; } static constexpr bool kindof(Object::Kind kind) { return true; }
}; };
// cstr() returns the c-string name of the given Object::Kind.
constexpr const char *cstr(Object::Kind k)
{
switch(k)
{
case Object::Kind::Object: return "Object";
case Object::Kind::Declare: return "Declare";
case Object::Kind::Expression: return "Expression";
case Object::Kind::Function: return "Function";
case Object::Kind::InlinedAt: return "InlinedAt";
case Object::Kind::LocalVariable: return "LocalVariable";
case Object::Kind::Member: return "Member";
case Object::Kind::Operation: return "Operation";
case Object::Kind::Source: return "Source";
case Object::Kind::SourceScope: return "SourceScope";
case Object::Kind::Value: return "Value";
case Object::Kind::CompilationUnit: return "CompilationUnit";
case Object::Kind::LexicalBlock: return "LexicalBlock";
case Object::Kind::BasicType: return "BasicType";
case Object::Kind::VectorType: return "VectorType";
case Object::Kind::FunctionType: return "FunctionType";
case Object::Kind::CompositeType: return "CompositeType";
}
return "<unknown>";
}
template<typename TYPE_, typename BASE, Object::Kind KIND_> template<typename TYPE_, typename BASE, Object::Kind KIND_>
struct ObjectImpl : public BASE struct ObjectImpl : public BASE
{ {
...@@ -1044,8 +1070,8 @@ T *SpirvShader::Impl::Debugger::get(SpirvID<T> id) const ...@@ -1044,8 +1070,8 @@ T *SpirvShader::Impl::Debugger::get(SpirvID<T> id) const
auto it = objects.find(debug::Object::ID(id.value())); auto it = objects.find(debug::Object::ID(id.value()));
ASSERT_MSG(it != objects.end(), "Unknown debug object %d", id.value()); ASSERT_MSG(it != objects.end(), "Unknown debug object %d", id.value());
auto ptr = debug::cast<T>(it->second.get()); auto ptr = debug::cast<T>(it->second.get());
ASSERT_MSG(ptr, "Debug object %d is not of the correct type. Got: %d, want: %d", ASSERT_MSG(ptr, "Debug object %d is not of the correct type. Got: %s, want: %s",
id.value(), int(it->second->kind), int(T::KIND)); id.value(), cstr(it->second->kind), cstr(T::KIND));
return ptr; return ptr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment