]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Error.cpp
Merge ^/head r308870 through r309105.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / Error.cpp
1 //===- Error.cpp ----------------------------------------------------------===//
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 #include "Error.h"
11 #include "Config.h"
12
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/Support/Error.h"
15 #include "llvm/Support/raw_ostream.h"
16
17 using namespace llvm;
18
19 namespace lld {
20 namespace elf {
21
22 bool HasError;
23 raw_ostream *ErrorOS;
24
25 void log(const Twine &Msg) {
26   if (Config->Verbose)
27     outs() << Msg << "\n";
28 }
29
30 void warning(const Twine &Msg) {
31   if (Config->FatalWarnings)
32     error(Msg);
33   else
34     *ErrorOS << Msg << "\n";
35 }
36
37 void error(const Twine &Msg) {
38   *ErrorOS << Msg << "\n";
39   HasError = true;
40 }
41
42 void error(std::error_code EC, const Twine &Prefix) {
43   error(Prefix + ": " + EC.message());
44 }
45
46 void fatal(const Twine &Msg) {
47   *ErrorOS << Msg << "\n";
48   exit(1);
49 }
50
51 void fatal(const Twine &Msg, const Twine &Prefix) {
52   fatal(Prefix + ": " + Msg);
53 }
54
55 void check(std::error_code EC) {
56   if (EC)
57     fatal(EC.message());
58 }
59
60 void check(Error Err) {
61   check(errorToErrorCode(std::move(Err)));
62 }
63
64 } // namespace elf
65 } // namespace lld