]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Error.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303197, and update
[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 extern llvm::StringRef Argv0;
22
23 void log(const Twine &Msg);
24 void message(const Twine &Msg);
25 void warn(const Twine &Msg);
26 void error(const Twine &Msg);
27 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
28 LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
29 LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
30
31 template <class T> T check(ErrorOr<T> V, const Twine &Prefix) {
32   if (auto EC = V.getError())
33     fatal(EC, Prefix);
34   return std::move(*V);
35 }
36
37 template <class T> T check(Expected<T> E, const Twine &Prefix) {
38   if (llvm::Error Err = E.takeError())
39     fatal(Err, Prefix);
40   return std::move(*E);
41 }
42
43 template <class T> T check(ErrorOr<T> EO) {
44   if (!EO)
45     fatal(EO.getError().message());
46   return std::move(*EO);
47 }
48
49 template <class T> T check(Expected<T> E) {
50   if (!E) {
51     std::string Buf;
52     llvm::raw_string_ostream OS(Buf);
53     logAllUnhandledErrors(E.takeError(), OS, "");
54     OS.flush();
55     fatal(Buf);
56   }
57   return std::move(*E);
58 }
59
60 } // namespace coff
61 } // namespace lld
62
63 #endif