[llvm-commits] [llvm] r42815 - in /llvm/trunk: include/llvm/Support/MemoryBuffer.h lib/Support/MemoryBuffer.cpp

Chris Lattner sabre at nondot.org
Tue Oct 9 14:46:38 PDT 2007


Author: lattner
Date: Tue Oct  9 16:46:38 2007
New Revision: 42815

URL: http://llvm.org/viewvc/llvm-project?rev=42815&view=rev
Log:
Add new MemoryBuffer::getMemBufferCopy method.

Modified:
    llvm/trunk/include/llvm/Support/MemoryBuffer.h
    llvm/trunk/lib/Support/MemoryBuffer.cpp

Modified: llvm/trunk/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemoryBuffer.h?rev=42815&r1=42814&r2=42815&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/MemoryBuffer.h Tue Oct  9 16:46:38 2007
@@ -61,6 +61,12 @@
   static MemoryBuffer *getMemBuffer(const char *StartPtr, const char *EndPtr,
                                     const char *BufferName = "");
   
+  /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
+  /// copying the contents and taking ownership of it.  This has no requirements
+  /// on EndPtr[0].
+  static MemoryBuffer *getMemBufferCopy(const char *StartPtr,const char *EndPtr,
+                                        const char *BufferName = "");
+  
   /// getNewMemBuffer - Allocate a new MemoryBuffer of the specified size that
   /// is completely initialized to zeros.  Note that the caller should
   /// initialize the memory allocated by this method.  The memory is owned by

Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=42815&r1=42814&r2=42815&view=diff

==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Tue Oct  9 16:46:38 2007
@@ -59,9 +59,13 @@
 class MemoryBufferMem : public MemoryBuffer {
   std::string FileID;
 public:
-  MemoryBufferMem(const char *Start, const char *End, const char *FID)
+  MemoryBufferMem(const char *Start, const char *End, const char *FID,
+                  bool Copy = false)
   : FileID(FID) {
-    init(Start, End);
+    if (!Copy)
+      init(Start, End);
+    else
+      initCopyOf(Start, End);
   }
   
   virtual const char *getBufferIdentifier() const {
@@ -78,6 +82,15 @@
   return new MemoryBufferMem(StartPtr, EndPtr, BufferName);
 }
 
+/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
+/// copying the contents and taking ownership of it.  This has no requirements
+/// on EndPtr[0].
+MemoryBuffer *MemoryBuffer::getMemBufferCopy(const char *StartPtr, 
+                                             const char *EndPtr,
+                                             const char *BufferName) {
+  return new MemoryBufferMem(StartPtr, EndPtr, BufferName, true);
+}
+
 /// getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size
 /// that is completely initialized to zeros.  Note that the caller should
 /// initialize the memory allocated by this method.  The memory is owned by





More information about the llvm-commits mailing list