2015-12-30 11:57:38 +00:00
|
|
|
//===- Error.h --------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_COFF_ERROR_H
|
|
|
|
#define LLD_COFF_ERROR_H
|
|
|
|
|
|
|
|
#include "lld/Core/LLVM.h"
|
2016-07-23 20:48:50 +00:00
|
|
|
#include "llvm/Support/Error.h"
|
2015-12-30 11:57:38 +00:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace coff {
|
|
|
|
|
2016-07-23 20:48:50 +00:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
|
|
|
|
LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
|
|
|
|
LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
|
2015-12-30 11:57:38 +00:00
|
|
|
|
2016-07-23 20:48:50 +00:00
|
|
|
template <class T> T check(ErrorOr<T> &&V, const Twine &Prefix) {
|
|
|
|
if (auto EC = V.getError())
|
|
|
|
fatal(EC, Prefix);
|
|
|
|
return std::move(*V);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> T check(Expected<T> E, const Twine &Prefix) {
|
|
|
|
if (llvm::Error Err = E.takeError())
|
|
|
|
fatal(Err, Prefix);
|
|
|
|
return std::move(*E);
|
2015-12-30 11:57:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 19:19:15 +00:00
|
|
|
template <class T> T check(ErrorOr<T> EO) {
|
|
|
|
if (!EO)
|
|
|
|
fatal(EO.getError().message());
|
|
|
|
return std::move(*EO);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> T check(Expected<T> E) {
|
|
|
|
if (!E) {
|
|
|
|
std::string Buf;
|
|
|
|
llvm::raw_string_ostream OS(Buf);
|
|
|
|
logAllUnhandledErrors(E.takeError(), OS, "");
|
|
|
|
OS.flush();
|
|
|
|
fatal(Buf);
|
|
|
|
}
|
|
|
|
return std::move(*E);
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:57:38 +00:00
|
|
|
} // namespace coff
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|