1 //===- Error.h --------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_COFF_ERROR_H
11 #define LLD_COFF_ERROR_H
13 #include "lld/Core/LLVM.h"
14 #include "llvm/Support/Error.h"
19 extern uint64_t ErrorCount;
20 extern llvm::raw_ostream *ErrorOS;
21 extern llvm::StringRef Argv0;
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);
31 template <class T> T check(ErrorOr<T> V, const Twine &Prefix) {
32 if (auto EC = V.getError())
37 template <class T> T check(Expected<T> E, const Twine &Prefix) {
38 if (llvm::Error Err = E.takeError())
43 template <class T> T check(ErrorOr<T> EO) {
45 fatal(EO.getError().message());
46 return std::move(*EO);
49 template <class T> T check(Expected<T> E) {
52 llvm::raw_string_ostream OS(Buf);
53 logAllUnhandledErrors(E.takeError(), OS, "");