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 <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/dawn_node/utils/Debug.h b/src/dawn_node/utils/Debug.h
index d9551f6..96c1986 100644
--- a/src/dawn_node/utils/Debug.h
+++ b/src/dawn_node/utils/Debug.h
@@ -17,6 +17,7 @@
#include <iostream>
#include <optional>
+#include <sstream>
#include <unordered_map>
#include <variant>
#include <vector>
@@ -101,12 +102,22 @@
}
// 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 <typename... MSG_ARGS>
+ [[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>(msg_args)...);
+ }
+ std::cout << msg.str() << std::endl;
abort();
}
@@ -118,10 +129,11 @@
<< 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