blob: 500d7295e69468ae0e3fb3bc78d654da85560e5f [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);
Zachary Turner5e3e4bb2016-08-05 21:45:34 +000025 void error(std::error_code EC);
Zachary Turner660230e2016-08-04 19:39:55 +000026 void error(llvm::Error EC);
Zachary Turner2d5c2cd2017-05-03 17:11:11 +000027 template <typename T> T error(llvm::Expected<T> &&E) {
28 error(E.takeError());
29 return std::move(*E);
30 }
31
Rafael Espindolaf04f1842016-02-17 16:21:49 +000032 template <class T> T unwrapOrError(ErrorOr<T> EO) {
33 if (EO)
34 return *EO;
35 reportError(EO.getError().message());
36 }
Kevin Enderby81e8b7d2016-04-20 21:24:34 +000037 template <class T> T unwrapOrError(Expected<T> EO) {
38 if (EO)
39 return *EO;
40 std::string Buf;
41 raw_string_ostream OS(Buf);
Jonas Devlieghere45eb84f2018-11-11 01:46:03 +000042 logAllUnhandledErrors(EO.takeError(), OS);
Kevin Enderby81e8b7d2016-04-20 21:24:34 +000043 OS.flush();
44 reportError(Buf);
45 }
Eric Christopher9cad53c2013-04-03 18:31:38 +000046 bool relocAddressLess(object::RelocationRef A,
47 object::RelocationRef B);
48} // namespace llvm
49
50namespace opts {
Eric Christopher9cad53c2013-04-03 18:31:38 +000051 extern llvm::cl::opt<bool> SectionRelocations;
52 extern llvm::cl::opt<bool> SectionSymbols;
53 extern llvm::cl::opt<bool> SectionData;
Nico Rieckf3f0b792013-04-12 04:01:52 +000054 extern llvm::cl::opt<bool> ExpandRelocs;
Jake Ehrlich0f440d82018-06-28 21:07:34 +000055 extern llvm::cl::opt<bool> RawRelr;
Zachary Turner99f02152015-02-18 19:32:05 +000056 extern llvm::cl::opt<bool> CodeViewSubsectionBytes;
James Hendersone50d9cb2019-01-17 15:34:12 +000057 extern llvm::cl::opt<bool> Demangle;
Tim Northoverd59b23a2016-03-01 21:45:22 +000058 enum OutputStyleTy { LLVM, GNU };
59 extern llvm::cl::opt<OutputStyleTy> Output;
Eric Christopher9cad53c2013-04-03 18:31:38 +000060} // namespace opts
61
62#define LLVM_READOBJ_ENUM_ENT(ns, enum) \
63 { #enum, ns::enum }
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000064
Reid Kleckner72e2ba72016-01-13 19:32:35 +000065#define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \
66 { #enum, std::underlying_type<enum_class>::type(enum_class::enum) }
67
Michael J. Spencer6a8746b2013-02-20 02:37:12 +000068#endif