]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Error.h
Bring lld (release_39 branch, r279477) to contrib
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / 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
15 namespace lld {
16 namespace elf {
17
18 extern bool HasError;
19 extern llvm::raw_ostream *ErrorOS;
20
21 void log(const Twine &Msg);
22 void warning(const Twine &Msg);
23
24 void error(const Twine &Msg);
25 void error(std::error_code EC, const Twine &Prefix);
26
27 template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
28   error(V.getError(), Prefix);
29 }
30
31 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
32 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg, const Twine &Prefix);
33
34 template <class T> T check(ErrorOr<T> E) {
35   if (auto EC = E.getError())
36     fatal(EC.message());
37   return std::move(*E);
38 }
39
40 template <class T> T check(Expected<T> E) {
41   if (!E)
42     fatal(errorToErrorCode(E.takeError()).message());
43   return std::move(*E);
44 }
45
46 template <class T> T check(ErrorOr<T> E, const Twine &Prefix) {
47   if (auto EC = E.getError())
48     fatal(EC.message(), Prefix);
49   return std::move(*E);
50 }
51
52 template <class T> T check(Expected<T> E, const Twine &Prefix) {
53   if (!E)
54     fatal(errorToErrorCode(E.takeError()).message(), Prefix);
55   return std::move(*E);
56 }
57
58 } // namespace elf
59 } // namespace lld
60
61 #endif