[llvm-commits] [llvm] r120190 - in /llvm/trunk: include/llvm/Object/MachOObject.h lib/Object/CMakeLists.txt lib/Object/MachOObject.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 26 21:38:50 PST 2010


Author: ddunbar
Date: Fri Nov 26 23:38:50 2010
New Revision: 120190

URL: http://llvm.org/viewvc/llvm-project?rev=120190&view=rev
Log:
MC/Mach-O: Start stubbing out a Mach-O object file wrapper.

Added:
    llvm/trunk/include/llvm/Object/MachOObject.h
    llvm/trunk/lib/Object/MachOObject.cpp
Modified:
    llvm/trunk/lib/Object/CMakeLists.txt

Added: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=120190&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (added)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Fri Nov 26 23:38:50 2010
@@ -0,0 +1,69 @@
+//===- MachOObject.h - Mach-O Object File Wrapper ---------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_OBJECT_MACHOOBJECT_H
+#define LLVM_OBJECT_MACHOOBJECT_H
+
+#include <string>
+#include "llvm/ADT/OwningPtr.h"
+
+namespace llvm {
+
+class MemoryBuffer;
+
+namespace object {
+
+/// \brief Wrapper object for manipulating Mach-O object files.
+///
+/// This class is designed to implement a full-featured, efficient, portable,
+/// and robust Mach-O interface to Mach-O object files. It does not attempt to
+/// smooth over rough edges in the Mach-O format or generalize access to object
+/// independent features.
+///
+/// The class is designed around accessing the Mach-O object which is expected
+/// to be fully loaded into memory.
+///
+/// This class is *not* suitable for concurrent use. For efficient operation,
+/// the class uses APIs which rely on the ability to cache the results of
+/// certain calls in internal objects which are not safe for concurrent
+/// access. This allows the API to be zero-copy on the common paths.
+//
+// FIXME: It would be cool if we supported a "paged" MemoryBuffer
+// implementation. This would allow us to implement a more sensible version of
+// MemoryObject which can work like a MemoryBuffer, but be more efficient for
+// objects which are in the current address space.
+class MachOObject {
+public:
+
+private:
+  OwningPtr<MemoryBuffer> Buffer;
+  
+public:
+  MachOObject(MemoryBuffer *Buffer);
+
+  /// \brief Load a Mach-O object from a MemoryBuffer object.
+  ///
+  /// \param Buffer - The buffer to load the object from. This routine takes
+  /// exclusive ownership of the buffer (which is passed to the returned object
+  /// on success).
+  /// \param ErrorStr [out] - If given, will be set to a user readable error
+  /// message on failure.
+  /// \returns The loaded object, or null on error.
+  static MachOObject *LoadFromBuffer(MemoryBuffer *Buffer,
+                                     std::string *ErrorStr = 0);
+
+  /// @name Object Header Information
+  /// @{
+  /// @}
+};
+
+} // end namespace object
+} // end namespace llvm
+
+#endif

Modified: llvm/trunk/lib/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/CMakeLists.txt?rev=120190&r1=120189&r2=120190&view=diff
==============================================================================
--- llvm/trunk/lib/Object/CMakeLists.txt (original)
+++ llvm/trunk/lib/Object/CMakeLists.txt Fri Nov 26 23:38:50 2010
@@ -1,3 +1,4 @@
 add_llvm_library(LLVMObject
+  MachOObject.cpp
   ObjectFile.cpp
   )

Added: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=120190&view=auto
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (added)
+++ llvm/trunk/lib/Object/MachOObject.cpp Fri Nov 26 23:38:50 2010
@@ -0,0 +1,23 @@
+//===- MachOObject.cpp - Mach-O Object File Wrapper -----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/MachOObject.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+using namespace object;
+
+MachOObject::MachOObject(MemoryBuffer *Buffer_) : Buffer(Buffer_) {
+}
+
+MachOObject *MachOObject::LoadFromBuffer(MemoryBuffer *Buffer,
+                                         std::string *ErrorStr) {
+  if (ErrorStr) *ErrorStr = "";
+  return new MachOObject(Buffer);
+}





More information about the llvm-commits mailing list