MC/Mach-O: Start stubbing out a Mach-O object file wrapper.
[oota-llvm.git] / include / llvm / Object / MachOObject.h
1 //===- MachOObject.h - Mach-O Object File Wrapper ---------------*- 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 #ifndef LLVM_OBJECT_MACHOOBJECT_H
11 #define LLVM_OBJECT_MACHOOBJECT_H
12
13 #include <string>
14 #include "llvm/ADT/OwningPtr.h"
15
16 namespace llvm {
17
18 class MemoryBuffer;
19
20 namespace object {
21
22 /// \brief Wrapper object for manipulating Mach-O object files.
23 ///
24 /// This class is designed to implement a full-featured, efficient, portable,
25 /// and robust Mach-O interface to Mach-O object files. It does not attempt to
26 /// smooth over rough edges in the Mach-O format or generalize access to object
27 /// independent features.
28 ///
29 /// The class is designed around accessing the Mach-O object which is expected
30 /// to be fully loaded into memory.
31 ///
32 /// This class is *not* suitable for concurrent use. For efficient operation,
33 /// the class uses APIs which rely on the ability to cache the results of
34 /// certain calls in internal objects which are not safe for concurrent
35 /// access. This allows the API to be zero-copy on the common paths.
36 //
37 // FIXME: It would be cool if we supported a "paged" MemoryBuffer
38 // implementation. This would allow us to implement a more sensible version of
39 // MemoryObject which can work like a MemoryBuffer, but be more efficient for
40 // objects which are in the current address space.
41 class MachOObject {
42 public:
43
44 private:
45   OwningPtr<MemoryBuffer> Buffer;
46   
47 public:
48   MachOObject(MemoryBuffer *Buffer);
49
50   /// \brief Load a Mach-O object from a MemoryBuffer object.
51   ///
52   /// \param Buffer - The buffer to load the object from. This routine takes
53   /// exclusive ownership of the buffer (which is passed to the returned object
54   /// on success).
55   /// \param ErrorStr [out] - If given, will be set to a user readable error
56   /// message on failure.
57   /// \returns The loaded object, or null on error.
58   static MachOObject *LoadFromBuffer(MemoryBuffer *Buffer,
59                                      std::string *ErrorStr = 0);
60
61   /// @name Object Header Information
62   /// @{
63   /// @}
64 };
65
66 } // end namespace object
67 } // end namespace llvm
68
69 #endif