blob: 10b083ecaee7ebb673aed30c48093250ec0e4dfc [file] [log] [blame]
Petr Hosek05a04cb2017-08-01 00:33:58 +00001//===- llvm-objcopy.h -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Eugene Zelenko0ad18f82017-11-01 21:16:06 +00009
10#ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H
11#define LLVM_TOOLS_OBJCOPY_OBJCOPY_H
Petr Hosek05a04cb2017-08-01 00:33:58 +000012
13#include "llvm/ADT/Twine.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000014#include "llvm/Support/Compiler.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000015#include "llvm/Support/Error.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000016#include "llvm/Support/raw_ostream.h"
17#include <string>
Petr Hosek05a04cb2017-08-01 00:33:58 +000018
19namespace llvm {
20
Zachary Turner41a9ee92017-10-11 23:54:34 +000021LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
Jake Ehrlich76e91102018-01-25 22:46:17 +000022LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
23LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File,
24 std::error_code EC);
Petr Hosek05a04cb2017-08-01 00:33:58 +000025
26// This is taken from llvm-readobj.
27// [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38)
28template <class T> T unwrapOrError(Expected<T> EO) {
29 if (EO)
30 return *EO;
31 std::string Buf;
32 raw_string_ostream OS(Buf);
33 logAllUnhandledErrors(EO.takeError(), OS, "");
34 OS.flush();
35 error(Buf);
36}
Petr Hosek05a04cb2017-08-01 00:33:58 +000037
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000038} // end namespace llvm
39
40#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H