From f5ea386698e84650ba50ec950b4172138dcafb1b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 9 Oct 2007 21:46:38 +0000 Subject: Add new MemoryBuffer::getMemBufferCopy method. llvm-svn: 42815 --- llvm/lib/Support/MemoryBuffer.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/MemoryBuffer.cpp') diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index 0ae5676acce..f8779e122d5 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -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 -- cgit v1.2.3