Add TINT_UNREACHABLE() and TINT_ICE() helper macros

Appends an error message with the tint compiler source location to the
provided diagnositic list, and then calls the global error handler if
one is set.
Tests and the sample app now register an error handler to print the
diagnostic list to stderr and abort when NDEBUG is not defined.

All uses of assert(false) have been fixed up to use these macros.

Change-Id: I2f63e51ed86ac23883301d280070bd1a357c6cb2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41620
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-02-17 20:13:34 +00:00
committed by Commit Bot service account
parent c7ca7668cc
commit 6b4924fb0e
35 changed files with 858 additions and 476 deletions

View File

@@ -28,6 +28,13 @@
namespace {
[[noreturn]]
void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
auto printer = tint::diag::Printer::create(stderr, true);
tint::diag::Formatter{}.format(diagnostics, printer.get());
exit(1);
}
enum class Format {
kNone = -1,
kSpirv,
@@ -419,6 +426,8 @@ int main(int argc, const char** argv) {
std::vector<std::string> args(argv, argv + argc);
Options options;
tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
if (!ParseArgs(args, &options)) {
std::cerr << "Failed to parse arguments." << std::endl;
return 1;