This allows us to create C interface with MessageLevel later.
DiagnosticStream::~DiagnosticStream() {
using spvtools::MessageLevel;
if (error_ != SPV_FAILED_MATCH && consumer_ != nullptr) {
- auto level = MessageLevel::Error;
+ auto level = MessageLevel::kError;
switch (error_) {
case SPV_SUCCESS:
case SPV_REQUESTED_TERMINATION: // Essentially success.
- level = MessageLevel::Info;
+ level = MessageLevel::kInfo;
break;
case SPV_WARNING:
- level = MessageLevel::Warning;
+ level = MessageLevel::kWarning;
break;
case SPV_UNSUPPORTED:
case SPV_ERROR_INTERNAL:
case SPV_ERROR_INVALID_TABLE:
- level = MessageLevel::InternalError;
+ level = MessageLevel::kInternalError;
break;
case SPV_ERROR_OUT_OF_MEMORY:
- level = MessageLevel::Fatal;
+ level = MessageLevel::kFatal;
break;
default:
break;
const char* message) {
const char* level_string = nullptr;
switch (level) {
- case MessageLevel::Fatal:
+ case MessageLevel::kFatal:
level_string = "fatal";
break;
- case MessageLevel::InternalError:
+ case MessageLevel::kInternalError:
level_string = "internal error";
break;
- case MessageLevel::Error:
+ case MessageLevel::kError:
level_string = "error";
break;
- case MessageLevel::Warning:
+ case MessageLevel::kWarning:
level_string = "warning";
break;
- case MessageLevel::Info:
+ case MessageLevel::kInfo:
level_string = "info";
break;
- case MessageLevel::Debug:
+ case MessageLevel::kDebug:
level_string = "debug";
break;
}
// TODO(antiagainst): This eventually should be in the C++ interface.
// Severity levels of messages communicated to the consumer.
-enum class MessageLevel {
- Fatal, // Unrecoverable error due to environment. Will abort the program
- // immediately. E.g., out of memory.
- InternalError, // Unrecoverable error due to SPIRV-Tools internals. Will
- // abort the program immediately. E.g., unimplemented feature.
- Error, // Normal error due to user input.
- Warning, // Warning information.
- Info, // General information.
- Debug, // Debug information.
+enum MessageLevel {
+ kFatal, // Unrecoverable error due to environment.
+ // Will exit the program immediately. E.g.,
+ // out of memory.
+ kInternalError, // Unrecoverable error due to SPIRV-Tools internals.
+ // Will exit the program immediately. E.g.,
+ // unimplemented feature.
+ kError, // Normal error due to user input.
+ kWarning, // Warning information.
+ kInfo, // General information.
+ kDebug, // Debug information.
};
// Message consumer. The C strings for source and message are only alive for the
// Logs an error message to the consumer saying the given feature is
// unimplemented.
-#define SPIRV_UNIMPLEMENTED(consumer, feature) \
- do { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "unimplemented: " feature); \
+#define SPIRV_UNIMPLEMENTED(consumer, feature) \
+ do { \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "unimplemented: " feature); \
} while (0)
// Logs an error message to the consumer saying the code location
// should be unreachable.
-#define SPIRV_UNREACHABLE(consumer) \
- do { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "unreachable"); \
+#define SPIRV_UNREACHABLE(consumer) \
+ do { \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "unreachable"); \
} while (0)
// Helper macros for concatenating arguments.
#define SPIRV_ASSERT_1(consumer, condition) \
do { \
if (!(condition)) { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
{__LINE__, 0, 0}, "assertion failed: " #condition); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
-#define SPIRV_ASSERT_2(consumer, condition, message) \
- do { \
- if (!(condition)) { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "assertion failed: " message); \
- std::exit(EXIT_FAILURE); \
- } \
- } while (0)
-
-#define SPIRV_ASSERT_more(consumer, condition, format, ...) \
+#define SPIRV_ASSERT_2(consumer, condition, message) \
do { \
if (!(condition)) { \
- spvtools::Logf(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "assertion failed: " format, \
- __VA_ARGS__); \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "assertion failed: " message); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
+#define SPIRV_ASSERT_more(consumer, condition, format, ...) \
+ do { \
+ if (!(condition)) { \
+ spvtools::Logf(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "assertion failed: " format, \
+ __VA_ARGS__); \
+ std::exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
#define SPIRV_ASSERT_3(consumer, condition, format, ...) \
SPIRV_ASSERT_more(consumer, condition, format, __VA_ARGS__)
ctx, [&invocation](spvtools::MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(spvtools::MessageLevel::Error, level);
+ EXPECT_EQ(spvtools::MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
// The error happens at scanning the begining of second line.
EXPECT_STREQ("input", source);
EXPECT_EQ(1u, position.line);
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
// This cannot pass validation since %1 is not defined.
t.SetMessageConsumer([](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(5u, position.column);
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
auto consumer = [&invocation](MessageLevel level, const char* source,
const spv_position_t&, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::InternalError, level);
+ EXPECT_EQ(MessageLevel::kInternalError, level);
EXPECT_THAT(source, MatchesRegex(".*test_log.cpp$"));
EXPECT_STREQ("unimplemented: the-ultimite-feature", message);
};
auto consumer = [&invocation](MessageLevel level, const char* source,
const spv_position_t&, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::InternalError, level);
+ EXPECT_EQ(MessageLevel::kInternalError, level);
EXPECT_THAT(source, MatchesRegex(".*test_log.cpp$"));
EXPECT_STREQ("unreachable", message);
};