blob: 92ed098dc6421cfe5f1bd8999fe0a65584ef520a [file] [log] [blame]
Eric Christopher76e70f32013-04-03 18:31:38 +00001//===-- llvm-readobj.h ----------------------------------------------------===//
Michael J. Spencerd326d052013-02-20 02:37:12 +00002//
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 Kramer00e08fc2014-08-13 16:26:38 +000010#ifndef LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
11#define LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
Michael J. Spencerd326d052013-02-20 02:37:12 +000012
Eric Christopher76e70f32013-04-03 18:31:38 +000013#include "llvm/Support/CommandLine.h"
Reid Klecknerefb247f2015-12-04 21:29:53 +000014#include "llvm/Support/Compiler.h"
Rafael Espindolabf33cfe2016-02-17 16:21:49 +000015#include "llvm/Support/ErrorOr.h"
Kevin Enderby813e0cf2016-04-20 21:24:34 +000016#include "llvm/Support/Error.h"
Eric Christopher76e70f32013-04-03 18:31:38 +000017#include <string>
Michael J. Spencerd326d052013-02-20 02:37:12 +000018
19namespace llvm {
Eric Christopher76e70f32013-04-03 18:31:38 +000020 namespace object {
21 class RelocationRef;
22 }
Michael J. Spencerd326d052013-02-20 02:37:12 +000023
Eric Christopher76e70f32013-04-03 18:31:38 +000024 // Various helper functions.
Reid Klecknerefb247f2015-12-04 21:29:53 +000025 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
Zachary Turner3483f212016-08-05 21:45:34 +000026 void error(std::error_code EC);
Zachary Turner92cd0ec2016-08-04 19:39:55 +000027 void error(llvm::Error EC);
Zachary Turnerf393f97e2017-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 Espindolabf33cfe2016-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 Enderby813e0cf2016-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 Devlieghere686dfe32018-11-11 01:46:03 +000043 logAllUnhandledErrors(EO.takeError(), OS);
Kevin Enderby813e0cf2016-04-20 21:24:34 +000044 OS.flush();
45 reportError(Buf);
46 }
Eric Christopher76e70f32013-04-03 18:31:38 +000047 bool relocAddressLess(object::RelocationRef A,
48 object::RelocationRef B);
49} // namespace llvm
50
51namespace opts {
Eric Christopher76e70f32013-04-03 18:31:38 +000052 extern llvm::cl::opt<bool> SectionRelocations;
53 extern llvm::cl::opt<bool> SectionSymbols;
54 extern llvm::cl::opt<bool> SectionData;
Eric Christopher76e70f32013-04-03 18:31:38 +000055 extern llvm::cl::opt<bool> DynamicSymbols;
Nico Rieck1c8dfa52013-04-12 04:01:52 +000056 extern llvm::cl::opt<bool> ExpandRelocs;
Jake Ehrlicheefdbb42018-06-28 21:07:34 +000057 extern llvm::cl::opt<bool> RawRelr;
Zachary Turner23719012015-02-18 19:32:05 +000058 extern llvm::cl::opt<bool> CodeViewSubsectionBytes;
Tim Northover9645a0d2016-03-01 21:45:22 +000059 enum OutputStyleTy { LLVM, GNU };
60 extern llvm::cl::opt<OutputStyleTy> Output;
Eric Christopher76e70f32013-04-03 18:31:38 +000061} // namespace opts
62
63#define LLVM_READOBJ_ENUM_ENT(ns, enum) \
64 { #enum, ns::enum }
Michael J. Spencerd326d052013-02-20 02:37:12 +000065
Reid Klecknerfb30f092016-01-13 19:32:35 +000066#define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \
67 { #enum, std::underlying_type<enum_class>::type(enum_class::enum) }
68
Michael J. Spencerd326d052013-02-20 02:37:12 +000069#endif