Add new MemoryBuffer::getMemBufferCopy method.
authorChris Lattner <sabre@nondot.org>
Tue, 9 Oct 2007 21:46:38 +0000 (21:46 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 9 Oct 2007 21:46:38 +0000 (21:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42815 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/MemoryBuffer.h
lib/Support/MemoryBuffer.cpp

index 1e3a154ede6713ddf5915fad149f33f9d223a911..aa13bfc65a8b05226bb92de2869fad09e486848f 100644 (file)
@@ -61,6 +61,12 @@ public:
   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
index 0ae5676acce367bcff7d58129e8da77599cf9677..f8779e122d5012de64621c8e1c1136d7c5f116a9 100644 (file)
@@ -59,9 +59,13 @@ namespace {
 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 @@ MemoryBuffer *MemoryBuffer::getMemBuffer(const char *StartPtr,
   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