blob: 4a5b8af191f17448556a66eddbe8cd7970f187dc [file] [log] [blame]
Rafael Espindola192e1fa2015-08-06 15:08:23 +00001//===- 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
12#include "llvm/ADT/Twine.h"
13#include "llvm/Support/raw_ostream.h"
14
15namespace lld {
16namespace elf2 {
17
Rui Ueyama64cfffd2016-01-28 18:40:06 +000018bool HasError;
Rui Ueyamab6940112016-02-02 22:49:32 +000019llvm::raw_ostream *ErrorOS;
Rui Ueyama64cfffd2016-01-28 18:40:06 +000020
Rui Ueyamad5b5ab72015-09-24 18:55:33 +000021void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; }
22
Rafael Espindola192e1fa2015-08-06 15:08:23 +000023void error(const Twine &Msg) {
Rui Ueyamab6940112016-02-02 22:49:32 +000024 *ErrorOS << Msg << "\n";
Rui Ueyama64cfffd2016-01-28 18:40:06 +000025 HasError = true;
Rafael Espindola192e1fa2015-08-06 15:08:23 +000026}
27
Rui Ueyama21eecb42016-02-02 21:13:09 +000028bool error(std::error_code EC, const Twine &Prefix) {
29 if (!EC)
30 return false;
31 error(Prefix + ": " + EC.message());
32 return true;
Rafael Espindola192e1fa2015-08-06 15:08:23 +000033}
34
Rui Ueyama21eecb42016-02-02 21:13:09 +000035bool error(std::error_code EC) {
36 if (!EC)
37 return false;
38 error(EC.message());
39 return true;
Rui Ueyama64cfffd2016-01-28 18:40:06 +000040}
41
42void fatal(const Twine &Msg) {
43 llvm::errs() << Msg << "\n";
44 exit(1);
45}
46
47void fatal(std::error_code EC, const Twine &Prefix) {
48 if (EC)
49 fatal(Prefix + ": " + EC.message());
50}
51
52void fatal(std::error_code EC) {
53 if (EC)
54 fatal(EC.message());
Rafael Espindola192e1fa2015-08-06 15:08:23 +000055}
56
57} // namespace elf2
58} // namespace lld