Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 1 | //===- llvm-objcopy.h -------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 0ad18f8 | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 8 | |
| 9 | #ifndef LLVM_TOOLS_OBJCOPY_OBJCOPY_H |
| 10 | #define LLVM_TOOLS_OBJCOPY_OBJCOPY_H |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/ADT/Twine.h" |
Eugene Zelenko | 0ad18f8 | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Compiler.h" |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Error.h" |
Eugene Zelenko | 0ad18f8 | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include <string> |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
Puyan Lotfi | 0f5d5fa | 2018-07-18 00:10:51 +0000 | [diff] [blame] | 19 | namespace objcopy { |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 20 | |
Zachary Turner | 41a9ee9 | 2017-10-11 23:54:34 +0000 | [diff] [blame] | 21 | LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message); |
Jordan Rupprecht | 881cae7 | 2019-01-22 23:49:16 +0000 | [diff] [blame] | 22 | LLVM_ATTRIBUTE_NORETURN extern void error(Error E); |
Jake Ehrlich | 76e9110 | 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 | 05a04cb | 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 | 45eb84f | 2018-11-11 01:46:03 +0000 | [diff] [blame] | 34 | logAllUnhandledErrors(EO.takeError(), OS); |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 35 | OS.flush(); |
| 36 | error(Buf); |
| 37 | } |
Petr Hosek | 05a04cb | 2017-08-01 00:33:58 +0000 | [diff] [blame] | 38 | |
Puyan Lotfi | 0f5d5fa | 2018-07-18 00:10:51 +0000 | [diff] [blame] | 39 | } // end namespace objcopy |
Eugene Zelenko | 0ad18f8 | 2017-11-01 21:16:06 +0000 | [diff] [blame] | 40 | } // end namespace llvm |
| 41 | |
| 42 | #endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H |