Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 66f724e | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H |
| 11 | #define LLVM_TOOLS_OBJCOPY_OBJCOPY_H |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 12 | |
| 13 | #include "llvm/ADT/Twine.h" |
Eugene Zelenko | 66f724e | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Compiler.h" |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Error.h" |
Eugene Zelenko | 66f724e | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | #include <string> |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
Puyan Lotfi | b5b60c3 | 2018-07-18 00:10:51 +0000 | [diff] [blame] | 20 | namespace objcopy { |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 21 | |
Zachary Turner | d411842 | 2017-10-11 23:54:34 +0000 | [diff] [blame] | 22 | LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message); |
Jake Ehrlich | ca099d9 | 2018-01-25 22:46:17 +0000 | [diff] [blame] | 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); |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 26 | |
| 27 | // This is taken from llvm-readobj. |
| 28 | // [see here](llvm/tools/llvm-readobj/llvm-readobj.h:38) |
| 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); |
Jonas Devlieghere | 686dfe3 | 2018-11-11 01:46:03 +0000 | [diff] [blame] | 34 | logAllUnhandledErrors(EO.takeError(), OS); |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 35 | OS.flush(); |
| 36 | error(Buf); |
| 37 | } |
Petr Hosek | e5551a7 | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 38 | |
Puyan Lotfi | b5b60c3 | 2018-07-18 00:10:51 +0000 | [diff] [blame] | 39 | } // end namespace objcopy |
Eugene Zelenko | 66f724e | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 40 | } // end namespace llvm |
| 41 | |
| 42 | #endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H |