From 7c9294584e25898d19a8ad2189ddcd33895809fc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 30 Sep 2021 13:09:24 +0000 Subject: [PATCH] dawn_node: Add message support to UNIMPLEMENTED() Have UNIMPLEMENTED() take a variadic set of message arguments which are printed with the fatal error message. Bug: dawn:1123 Change-Id: Idfa7ca71a8c59565434651a310d9e049349bb227 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65400 Reviewed-by: Corentin Wallez Commit-Queue: Ben Clayton --- src/dawn_node/utils/Debug.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/dawn_node/utils/Debug.h b/src/dawn_node/utils/Debug.h index d9551f660b..96c19863cd 100644 --- a/src/dawn_node/utils/Debug.h +++ b/src/dawn_node/utils/Debug.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -101,12 +102,22 @@ namespace wgpu { namespace utils { } // Unimplemented() prints an 'UNIMPLEMENTED' message to stdout with the given - // file, line and function, then calls abort(). + // file, line, function and optional message, then calls abort(). // Unimplemented() is usually not called directly, but by the UNIMPLEMENTED() // macro below. - [[noreturn]] inline void Unimplemented(const char* file, int line, const char* function) { - std::cout << file << ":" << line << ": " - << "UNIMPLEMENTED : " << function << std::endl; + template + [[noreturn]] inline void Unimplemented(const char* file, + int line, + const char* function, + MSG_ARGS&&... msg_args) { + std::stringstream msg; + msg << file << ":" << line << ": " + << "UNIMPLEMENTED: " << function << "()"; + if constexpr (sizeof...(msg_args)) { + msg << " "; + Write(msg, std::forward(msg_args)...); + } + std::cout << msg.str() << std::endl; abort(); } @@ -118,10 +129,11 @@ namespace wgpu { namespace utils { << std::endl // UNIMPLEMENTED() prints 'UNIMPLEMENTED' with the current file, line and -// function to stdout, then calls abort(). +// function to stdout, along with the optional message, then calls abort(). // The macro calls Unimplemented(), which is annotated with [[noreturn]]. // Used to stub code that has not yet been implemented. -#define UNIMPLEMENTED() ::wgpu::utils::Unimplemented(__FILE__, __LINE__, __FUNCTION__) +#define UNIMPLEMENTED(...) \ + ::wgpu::utils::Unimplemented(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) }} // namespace wgpu::utils