1 //===- 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 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H
11 #define LLVM_TOOLS_OBJCOPY_OBJCOPY_H
12 
13 #include "llvm/ADT/Twine.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/Support/Error.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include <string>
18 
19 namespace llvm {
20 namespace objcopy {
21 
22 LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
23 LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
24 LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File,
25                                                 std::error_code EC);
26 
27 // This is taken from llvm-readobj.
28 // [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38)
unwrapOrError(Expected<T> EO)29 template <class T> T unwrapOrError(Expected<T> EO) {
30   if (EO)
31     return *EO;
32   std::string Buf;
33   raw_string_ostream OS(Buf);
34   logAllUnhandledErrors(EO.takeError(), OS, "");
35   OS.flush();
36   error(Buf);
37 }
38 
39 } // end namespace objcopy
40 } // end namespace llvm
41 
42 #endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H
43