Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 1 | //===-- llvm-readobj.h ----------------------------------------------------===// |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 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 |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 9 | #ifndef LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H |
| 10 | #define LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 11 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 12 | #include "llvm/Support/CommandLine.h" |
Reid Kleckner | 9f23516 | 2015-12-04 21:29:53 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Compiler.h" |
Rafael Espindola | f04f184 | 2016-02-17 16:21:49 +0000 | [diff] [blame] | 14 | #include "llvm/Support/ErrorOr.h" |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Error.h" |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 16 | #include <string> |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 19 | namespace object { |
| 20 | class RelocationRef; |
| 21 | } |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 22 | |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 23 | // Various helper functions. |
Reid Kleckner | 9f23516 | 2015-12-04 21:29:53 +0000 | [diff] [blame] | 24 | LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg); |
George Rimar | 72f821d | 2019-05-20 15:41:48 +0000 | [diff] [blame] | 25 | void reportWarning(Twine Msg); |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 26 | void error(std::error_code EC); |
Zachary Turner | 660230e | 2016-08-04 19:39:55 +0000 | [diff] [blame] | 27 | void error(llvm::Error EC); |
Zachary Turner | 2d5c2cd | 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 | f04f184 | 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 | 81e8b7d | 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 | 45eb84f | 2018-11-11 01:46:03 +0000 | [diff] [blame] | 43 | logAllUnhandledErrors(EO.takeError(), OS); |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 44 | OS.flush(); |
| 45 | reportError(Buf); |
| 46 | } |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 47 | } // namespace llvm |
| 48 | |
| 49 | namespace opts { |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 50 | extern llvm::cl::opt<bool> SectionRelocations; |
| 51 | extern llvm::cl::opt<bool> SectionSymbols; |
| 52 | extern llvm::cl::opt<bool> SectionData; |
Nico Rieck | f3f0b79 | 2013-04-12 04:01:52 +0000 | [diff] [blame] | 53 | extern llvm::cl::opt<bool> ExpandRelocs; |
Jake Ehrlich | 0f440d8 | 2018-06-28 21:07:34 +0000 | [diff] [blame] | 54 | extern llvm::cl::opt<bool> RawRelr; |
Zachary Turner | 99f0215 | 2015-02-18 19:32:05 +0000 | [diff] [blame] | 55 | extern llvm::cl::opt<bool> CodeViewSubsectionBytes; |
James Henderson | e50d9cb | 2019-01-17 15:34:12 +0000 | [diff] [blame] | 56 | extern llvm::cl::opt<bool> Demangle; |
Tim Northover | d59b23a | 2016-03-01 21:45:22 +0000 | [diff] [blame] | 57 | enum OutputStyleTy { LLVM, GNU }; |
| 58 | extern llvm::cl::opt<OutputStyleTy> Output; |
Eric Christopher | 9cad53c | 2013-04-03 18:31:38 +0000 | [diff] [blame] | 59 | } // namespace opts |
| 60 | |
| 61 | #define LLVM_READOBJ_ENUM_ENT(ns, enum) \ |
| 62 | { #enum, ns::enum } |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 63 | |
Reid Kleckner | 72e2ba7 | 2016-01-13 19:32:35 +0000 | [diff] [blame] | 64 | #define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \ |
| 65 | { #enum, std::underlying_type<enum_class>::type(enum_class::enum) } |
| 66 | |
Michael J. Spencer | 6a8746b | 2013-02-20 02:37:12 +0000 | [diff] [blame] | 67 | #endif |