]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Error.h
Update mandoc to 1.14.2
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / COFF / Error.h
1 //===- Error.h --------------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_COFF_ERROR_H
11 #define LLD_COFF_ERROR_H
12
13 #include "lld/Core/LLVM.h"
14 #include "llvm/Support/Error.h"
15
16 namespace lld {
17 namespace coff {
18
19 extern uint64_t ErrorCount;
20 extern llvm::raw_ostream *ErrorOS;
21
22 void log(const Twine &Msg);
23 void message(const Twine &Msg);
24 void warn(const Twine &Msg);
25 void error(const Twine &Msg);
26 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
27 LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
28 LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
29
30 template <class T> T check(ErrorOr<T> V, const Twine &Prefix) {
31   if (auto EC = V.getError())
32     fatal(EC, Prefix);
33   return std::move(*V);
34 }
35
36 template <class T> T check(Expected<T> E, const Twine &Prefix) {
37   if (llvm::Error Err = E.takeError())
38     fatal(Err, Prefix);
39   return std::move(*E);
40 }
41
42 template <class T> T check(ErrorOr<T> EO) {
43   if (!EO)
44     fatal(EO.getError().message());
45   return std::move(*EO);
46 }
47
48 template <class T> T check(Expected<T> E) {
49   if (!E) {
50     std::string Buf;
51     llvm::raw_string_ostream OS(Buf);
52     logAllUnhandledErrors(E.takeError(), OS, "");
53     OS.flush();
54     fatal(Buf);
55   }
56   return std::move(*E);
57 }
58
59 } // namespace coff
60 } // namespace lld
61
62 #endif