Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 1 | //===-- llvm-readobj.h ----------------------------------------------------===// |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 00e08fc | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H |
| 11 | #define LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 12 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 13 | #include "llvm/Support/CommandLine.h" |
Reid Kleckner | efb247f | 2015-12-04 21:29:53 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Compiler.h" |
Rafael Espindola | bf33cfe | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 15 | #include "llvm/Support/ErrorOr.h" |
Kevin Enderby | 813e0cf | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Error.h" |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 17 | #include <string> |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 20 | namespace object { |
| 21 | class RelocationRef; |
| 22 | } |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 23 | |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 24 | // Various helper functions. |
Reid Kleckner | efb247f | 2015-12-04 21:29:53 +0000 | [diff] [blame] | 25 | LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg); |
Zachary Turner | 3483f21 | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 26 | void error(std::error_code EC); |
Zachary Turner | 92cd0ec | 2016-08-04 19:39:55 +0000 | [diff] [blame] | 27 | void error(llvm::Error EC); |
Zachary Turner | f393f97e | 2017-05-03 17:11:11 +0000 | [diff] [blame] | 28 | template <typename T> T error(llvm::Expected<T> &&E) { |
| 29 | error(E.takeError()); |
| 30 | return std::move(*E); |
| 31 | } |
| 32 | |
Rafael Espindola | bf33cfe | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 33 | template <class T> T unwrapOrError(ErrorOr<T> EO) { |
| 34 | if (EO) |
| 35 | return *EO; |
| 36 | reportError(EO.getError().message()); |
| 37 | } |
Kevin Enderby | 813e0cf | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 38 | template <class T> T unwrapOrError(Expected<T> EO) { |
| 39 | if (EO) |
| 40 | return *EO; |
| 41 | std::string Buf; |
| 42 | raw_string_ostream OS(Buf); |
Jonas Devlieghere | 686dfe3 | 2018-11-11 01:46:03 +0000 | [diff] [blame] | 43 | logAllUnhandledErrors(EO.takeError(), OS); |
Kevin Enderby | 813e0cf | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 44 | OS.flush(); |
| 45 | reportError(Buf); |
| 46 | } |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 47 | bool relocAddressLess(object::RelocationRef A, |
| 48 | object::RelocationRef B); |
| 49 | } // namespace llvm |
| 50 | |
| 51 | namespace opts { |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 52 | extern llvm::cl::opt<bool> SectionRelocations; |
| 53 | extern llvm::cl::opt<bool> SectionSymbols; |
| 54 | extern llvm::cl::opt<bool> SectionData; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 55 | extern llvm::cl::opt<bool> DynamicSymbols; |
Nico Rieck | 1c8dfa5 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 56 | extern llvm::cl::opt<bool> ExpandRelocs; |
Jake Ehrlich | eefdbb4 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 57 | extern llvm::cl::opt<bool> RawRelr; |
Zachary Turner | 2371901 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 58 | extern llvm::cl::opt<bool> CodeViewSubsectionBytes; |
Tim Northover | 9645a0d | 2016-03-01 21:45:22 +0000 | [diff] [blame] | 59 | enum OutputStyleTy { LLVM, GNU }; |
| 60 | extern llvm::cl::opt<OutputStyleTy> Output; |
Eric Christopher | 76e70f3 | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 61 | } // namespace opts |
| 62 | |
| 63 | #define LLVM_READOBJ_ENUM_ENT(ns, enum) \ |
| 64 | { #enum, ns::enum } |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 65 | |
Reid Kleckner | fb30f09 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 66 | #define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \ |
| 67 | { #enum, std::underlying_type<enum_class>::type(enum_class::enum) } |
| 68 | |
Michael J. Spencer | d326d05 | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 69 | #endif |