Supply a default 'operator=' method.
[oota-llvm.git] / include / llvm / Object / MachOObject.h
index 90065810991029e9a48f23cfcbf60bf4d627cc6d..86f150a2940f1cc4211a6eb0a6f99dc50d047009 100644 (file)
 #include <string>
 #include "llvm/ADT/InMemoryStruct.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Object/MachOFormat.h"
 
 namespace llvm {
 
 class MemoryBuffer;
+class raw_ostream;
 
 namespace object {
 
@@ -59,6 +61,8 @@ private:
   bool Is64Bit;
   /// Whether the object is swapped endianness from the host.
   bool IsSwappedEndian;
+  /// Whether the string table has been registered.
+  bool HasStringTable;
 
   /// The cached information on the load commands.
   LoadCommandInfo *LoadCommands;
@@ -68,6 +72,9 @@ private:
   macho::Header Header;
   macho::Header64Ext Header64Ext;
 
+  /// Cache string table information.
+  StringRef StringTable;
+
 private:
   MachOObject(MemoryBuffer *Buffer, bool IsLittleEndian, bool Is64Bit);
 
@@ -96,6 +103,24 @@ public:
     return Is64Bit ? macho::Header64Size : macho::Header32Size;
   }
 
+  StringRef getData(size_t Offset, size_t Size) const;
+
+  /// @}
+  /// @name String Table Data
+  /// @{
+
+  StringRef getStringTableData() const {
+    assert(HasStringTable && "String table has not been registered!");
+    return StringTable;
+  }
+
+  StringRef getStringAtIndex(unsigned Index) const {
+    size_t End = getStringTableData().find('\0', Index);
+    return getStringTableData().slice(Index, End);
+  }
+
+  void RegisterStringTable(macho::SymtabLoadCommand &SLC);
+
   /// @}
   /// @name Object Header Access
   /// @{
@@ -125,10 +150,57 @@ public:
   void ReadDysymtabLoadCommand(
     const LoadCommandInfo &LCI,
     InMemoryStruct<macho::DysymtabLoadCommand> &Res) const;
+  void ReadLinkeditDataLoadCommand(
+    const LoadCommandInfo &LCI,
+    InMemoryStruct<macho::LinkeditDataLoadCommand> &Res) const;
+  void ReadIndirectSymbolTableEntry(
+    const macho::DysymtabLoadCommand &DLC,
+    unsigned Index,
+    InMemoryStruct<macho::IndirectSymbolTableEntry> &Res) const;
+  void ReadSection(
+    const LoadCommandInfo &LCI,
+    unsigned Index,
+    InMemoryStruct<macho::Section> &Res) const;
+  void ReadSection64(
+    const LoadCommandInfo &LCI,
+    unsigned Index,
+    InMemoryStruct<macho::Section64> &Res) const;
+  void ReadRelocationEntry(
+    uint64_t RelocationTableOffset, unsigned Index,
+    InMemoryStruct<macho::RelocationEntry> &Res) const;
+  void ReadSymbolTableEntry(
+    uint64_t SymbolTableOffset, unsigned Index,
+    InMemoryStruct<macho::SymbolTableEntry> &Res) const;
+  void ReadSymbol64TableEntry(
+    uint64_t SymbolTableOffset, unsigned Index,
+    InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
+  void ReadDataInCodeTableEntry(
+    uint64_t TableOffset, unsigned Index,
+    InMemoryStruct<macho::DataInCodeTableEntry> &Res) const;
+  void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
+
+  /// @}
+
+  /// @name Object Dump Facilities
+  /// @{
+  /// dump - Support for debugging, callable in GDB: V->dump()
+  //
+  void dump() const;
+  void dumpHeader() const;
+
+  /// print - Implement operator<< on Value.
+  ///
+  void print(raw_ostream &O) const;
+  void printHeader(raw_ostream &O) const;
 
   /// @}
 };
 
+inline raw_ostream &operator<<(raw_ostream &OS, const MachOObject &V) {
+  V.print(OS);
+  return OS;
+}
+
 } // end namespace object
 } // end namespace llvm