mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 11:21:40 +00:00
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>
70 lines
2.7 KiB
C++
70 lines
2.7 KiB
C++
// Copyright 2021 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef SRC_DEBUG_H_
|
|
#define SRC_DEBUG_H_
|
|
|
|
#include <string>
|
|
|
|
#include "src/diagnostic/diagnostic.h"
|
|
#include "src/diagnostic/formatter.h"
|
|
#include "src/diagnostic/printer.h"
|
|
|
|
namespace tint {
|
|
|
|
/// Function type used for registering an internal compiler error reporter
|
|
using InternalCompilerErrorReporter = void(const diag::List&);
|
|
|
|
/// Frees any memory allocated for reporting internal compiler errors.
|
|
/// Must only be called once on application termination.
|
|
/// If an internal compiler error is raised and this function is not called,
|
|
/// then memory will leak.
|
|
void FreeInternalCompilerErrors();
|
|
|
|
/// Sets the global error reporter to be called in case of internal compiler
|
|
/// errors.
|
|
/// @param reporter the error reporter
|
|
void SetInternalCompilerErrorReporter(InternalCompilerErrorReporter* reporter);
|
|
|
|
/// InternalCompilerError adds the internal compiler error message to the
|
|
/// diagnostics list, and then calls the InternalCompilerErrorReporter if one is
|
|
/// set.
|
|
/// @param file the file containing the ICE
|
|
/// @param line the line containing the ICE
|
|
/// @param msg the ICE message
|
|
/// @param diagnostics the list of diagnostics to append the ICE message to
|
|
void InternalCompilerError(const char* file,
|
|
size_t line,
|
|
const std::string& msg,
|
|
diag::List& diagnostics);
|
|
|
|
} // namespace tint
|
|
|
|
/// TINT_ICE() is a macro for appending an internal compiler error message
|
|
/// to the diagnostics list `diagnostics`, and calling the
|
|
/// InternalCompilerErrorReporter with the full diagnostic list if a reporter is
|
|
/// set.
|
|
/// The ICE message contains the callsite's file and line.
|
|
#define TINT_ICE(diagnostics, msg) \
|
|
tint::InternalCompilerError(__FILE__, __LINE__, msg, diagnostics)
|
|
|
|
/// TINT_UNREACHABLE() is a macro for appending a "TINT_UNREACHABLE"
|
|
/// internal compiler error message to the diagnostics list `diagnostics`, and
|
|
/// calling the InternalCompilerErrorReporter with the full diagnostic list if a
|
|
/// reporter is set.
|
|
/// The ICE message contains the callsite's file and line.
|
|
#define TINT_UNREACHABLE(diagnostics) TINT_ICE(diagnostics, "TINT_UNREACHABLE")
|
|
|
|
#endif // SRC_DEBUG_H_
|