07faba758452ec87f79511ce50af39dbe850ea5e
[oota-llvm.git] / include / llvm / Support / ErrorHandling.h
1 //===- llvm/Support/ErrorHandling.h - Callbacks for errors ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines an API used to indicate error conditions.
11 // Callbacks can be registered for these errors through this API.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_ERRORHANDLING_H
16 #define LLVM_SUPPORT_ERRORHANDLING_H
17
18 #include "llvm/Support/Compiler.h"
19 #include <string>
20
21 namespace llvm {
22   /// An error handler callback.
23   typedef void (*llvm_error_handler_t)(const std::string& reason);
24
25   /// Installs a new error handler: this function will be called whenever a
26   /// serious error is encountered by LLVM.
27   /// If you are using llvm_start_multithreaded, you should register the handler
28   /// before doing that.
29   ///
30   /// If no error handler is installed the default is to print the error message
31   /// to stderr, and call exit(1).
32   /// If an error handler is installed then it is the handler's responsibility
33   /// to log the message, it will no longer be printed to stderr.
34   /// If the error handler returns, then exit(1) will be called.
35   void llvm_install_error_handler(llvm_error_handler_t handler);
36
37   /// Restores default error handling behaviour.
38   /// This must not be called between llvm_start_multithreaded() and
39   /// llvm_stop_multithreaded().
40   void llvm_remove_error_handler(void);
41
42   /// Reports a serious error, calling any installed error handler.
43   /// If no error handler is installed the default is to print the message to
44   /// standard error, followed by a newline.
45   /// After the error handler is called this function will call exit(1), it 
46   /// does not return.
47   void llvm_report_error(const std::string &reason) NORETURN;
48
49   /// This function calls abort(), and prints the optional message to stderr.
50   /// Call this instead of assert(0), so that compiler knows the path is not
51   /// reachable even for NDEBUG builds.
52   void llvm_unreachable(const char *msg=0) NORETURN;
53 }
54
55 #ifndef NDEBUG
56 #define LLVM_UNREACHABLE(msg) llvm_unreachable(msg)
57 #else
58 #define LLVM_UNREACHABLE(msg) llvm_unreachable()
59 #endif
60
61 #endif
62