Add an accessor to get the underlying MachO representation.
[oota-llvm.git] / include / llvm / Object / MachO.h
1 //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
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 //
10 // This file declares the MachOObjectFile class, which binds the MachOObject
11 // class to the generic ObjectFile wrapper.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_OBJECT_MACHO_H
16 #define LLVM_OBJECT_MACHO_H
17
18 #include "llvm/Object/ObjectFile.h"
19 #include "llvm/Object/MachOObject.h"
20 #include "llvm/Support/MachO.h"
21 #include "llvm/ADT/SmallVector.h"
22
23 namespace llvm {
24 namespace object {
25
26 typedef MachOObject::LoadCommandInfo LoadCommandInfo;
27
28 class MachOObjectFile : public ObjectFile {
29 public:
30   MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO, error_code &ec);
31
32   virtual symbol_iterator begin_symbols() const;
33   virtual symbol_iterator end_symbols() const;
34   virtual section_iterator begin_sections() const;
35   virtual section_iterator end_sections() const;
36
37   virtual uint8_t getBytesInAddress() const;
38   virtual StringRef getFileFormatName() const;
39   virtual unsigned getArch() const;
40
41   MachOObject *getObject() { return MachOObj; }
42
43 protected:
44   virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
45   virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
46   virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
47   virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
48   virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
49   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
50   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
51   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
52   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
53
54   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
55   virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
56   virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
57   virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
58   virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
59   virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const;
60   virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
61   virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const;
62   virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
63   virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
64                                            bool &Result) const;
65   virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
66   virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
67
68   virtual error_code getRelocationNext(DataRefImpl Rel,
69                                        RelocationRef &Res) const;
70   virtual error_code getRelocationAddress(DataRefImpl Rel,
71                                           uint64_t &Res) const;
72   virtual error_code getRelocationSymbol(DataRefImpl Rel,
73                                          SymbolRef &Res) const;
74   virtual error_code getRelocationType(DataRefImpl Rel,
75                                        uint32_t &Res) const;
76   virtual error_code getRelocationTypeName(DataRefImpl Rel,
77                                            SmallVectorImpl<char> &Result) const;
78   virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
79                                                  int64_t &Res) const;
80   virtual error_code getRelocationValueString(DataRefImpl Rel,
81                                            SmallVectorImpl<char> &Result) const;
82
83 private:
84   MachOObject *MachOObj;
85   mutable uint32_t RegisteredStringTable;
86   typedef SmallVector<DataRefImpl, 1> SectionList;
87   SectionList Sections;
88
89
90   void moveToNextSection(DataRefImpl &DRI) const;
91   void getSymbolTableEntry(DataRefImpl DRI,
92                            InMemoryStruct<macho::SymbolTableEntry> &Res) const;
93   void getSymbol64TableEntry(DataRefImpl DRI,
94                           InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
95   void moveToNextSymbol(DataRefImpl &DRI) const;
96   void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
97   void getSection64(DataRefImpl DRI,
98                     InMemoryStruct<macho::Section64> &Res) const;
99   void getRelocation(DataRefImpl Rel,
100                      InMemoryStruct<macho::RelocationEntry> &Res) const;
101   std::size_t getSectionIndex(DataRefImpl Sec) const;
102 };
103
104 }
105 }
106
107 #endif
108