blob: 75b460410c86207ef176c282fc45e929f3577c88 [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"
Rui Ueyama10bd2832016-02-25 18:56:01 +000011#include "Config.h"
Rafael Espindola192e1fa2015-08-06 15:08:23 +000012
13#include "llvm/ADT/Twine.h"
14#include "llvm/Support/raw_ostream.h"
15
16namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000017namespace elf {
Rafael Espindola192e1fa2015-08-06 15:08:23 +000018
Rui Ueyama64cfffd2016-01-28 18:40:06 +000019bool HasError;
Rui Ueyamab6940112016-02-02 22:49:32 +000020llvm::raw_ostream *ErrorOS;
Rui Ueyama64cfffd2016-01-28 18:40:06 +000021
Rui Ueyama10bd2832016-02-25 18:56:01 +000022void log(const Twine &Msg) {
23 if (Config->Verbose)
24 llvm::outs() << Msg << "\n";
25}
26
Rui Ueyamad5b5ab72015-09-24 18:55:33 +000027void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; }
28
Rafael Espindola192e1fa2015-08-06 15:08:23 +000029void error(const Twine &Msg) {
Rui Ueyamab6940112016-02-02 22:49:32 +000030 *ErrorOS << Msg << "\n";
Rui Ueyama64cfffd2016-01-28 18:40:06 +000031 HasError = true;
Rafael Espindola192e1fa2015-08-06 15:08:23 +000032}
33
Rui Ueyama21eecb42016-02-02 21:13:09 +000034bool error(std::error_code EC, const Twine &Prefix) {
35 if (!EC)
36 return false;
37 error(Prefix + ": " + EC.message());
38 return true;
Rafael Espindola192e1fa2015-08-06 15:08:23 +000039}
40
Rui Ueyama21eecb42016-02-02 21:13:09 +000041bool error(std::error_code EC) {
42 if (!EC)
43 return false;
44 error(EC.message());
45 return true;
Rui Ueyama64cfffd2016-01-28 18:40:06 +000046}
47
48void fatal(const Twine &Msg) {
49 llvm::errs() << Msg << "\n";
50 exit(1);
51}
52
53void fatal(std::error_code EC, const Twine &Prefix) {
54 if (EC)
55 fatal(Prefix + ": " + EC.message());
56}
57
58void fatal(std::error_code EC) {
59 if (EC)
60 fatal(EC.message());
Rafael Espindola192e1fa2015-08-06 15:08:23 +000061}
62
Rafael Espindolae0df00b2016-02-28 00:25:54 +000063} // namespace elf
Rafael Espindola192e1fa2015-08-06 15:08:23 +000064} // namespace lld