blob: c89871fbc7e1fc31a215cf9a5fe75bcc471618e1 [file] [log] [blame]
Eric Christopher9cad53c2013-04-03 18:31:38 +00001//===-- llvm-readobj.h ----------------------------------------------------===//
Michael J. Spencer6a8746b2013-02-20 02:37:12 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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. Spencer6a8746b2013-02-20 02:37:12 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
10#define LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000011
Eric Christopher9cad53c2013-04-03 18:31:38 +000012#include "llvm/Support/CommandLine.h"
Reid Kleckner9f235162015-12-04 21:29:53 +000013#include "llvm/Support/Compiler.h"
Rafael Espindolaf04f1842016-02-17 16:21:49 +000014#include "llvm/Support/ErrorOr.h"
Kevin Enderby81e8b7d2016-04-20 21:24:34 +000015#include "llvm/Support/Error.h"
Eric Christopher9cad53c2013-04-03 18:31:38 +000016#include <string>
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000017
18namespace llvm {
Eric Christopher9cad53c2013-04-03 18:31:38 +000019 namespace object {
20 class RelocationRef;
21 }
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000022
Eric Christopher9cad53c2013-04-03 18:31:38 +000023 // Various helper functions.
Reid Kleckner9f235162015-12-04 21:29:53 +000024 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
George Rimar72f821d2019-05-20 15:41:48 +000025 void reportWarning(Twine Msg);
Zachary Turner5e3e4bb2016-08-05 21:45:34 +000026 void error(std::error_code EC);
Zachary Turner660230e2016-08-04 19:39:55 +000027 void error(llvm::Error EC);
Zachary Turner2d5c2cd2017-05-03 17:11:11 +000028 template <typename T> T error(llvm::Expected<T> &&E) {
29 error(E.takeError());
30 return std::move(*E);
31 }
32
Rafael Espindolaf04f1842016-02-17 16:21:49 +000033 template <class T> T unwrapOrError(ErrorOr<T> EO) {
34 if (EO)
35 return *EO;
36 reportError(EO.getError().message());
37 }
Kevin Enderby81e8b7d2016-04-20 21:24:34 +000038 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 Devlieghere45eb84f2018-11-11 01:46:03 +000043 logAllUnhandledErrors(EO.takeError(), OS);
Kevin Enderby81e8b7d2016-04-20 21:24:34 +000044 OS.flush();
45 reportError(Buf);
46 }
Eric Christopher9cad53c2013-04-03 18:31:38 +000047} // namespace llvm
48
49namespace opts {
Eric Christopher9cad53c2013-04-03 18:31:38 +000050 extern llvm::cl::opt<bool> SectionRelocations;
51 extern llvm::cl::opt<bool> SectionSymbols;
52 extern llvm::cl::opt<bool> SectionData;
Nico Rieckf3f0b792013-04-12 04:01:52 +000053 extern llvm::cl::opt<bool> ExpandRelocs;
Jake Ehrlich0f440d82018-06-28 21:07:34 +000054 extern llvm::cl::opt<bool> RawRelr;
Zachary Turner99f02152015-02-18 19:32:05 +000055 extern llvm::cl::opt<bool> CodeViewSubsectionBytes;
James Hendersone50d9cb2019-01-17 15:34:12 +000056 extern llvm::cl::opt<bool> Demangle;
Tim Northoverd59b23a2016-03-01 21:45:22 +000057 enum OutputStyleTy { LLVM, GNU };
58 extern llvm::cl::opt<OutputStyleTy> Output;
Eric Christopher9cad53c2013-04-03 18:31:38 +000059} // namespace opts
60
61#define LLVM_READOBJ_ENUM_ENT(ns, enum) \
62 { #enum, ns::enum }
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000063
Reid Kleckner72e2ba72016-01-13 19:32:35 +000064#define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \
65 { #enum, std::underlying_type<enum_class>::type(enum_class::enum) }
66
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000067#endif