aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/MemoryBuffer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-09 21:46:38 +0000
committerChris Lattner <sabre@nondot.org>2007-10-09 21:46:38 +0000
commit3daae2701b76293c31c1cbdafc9782352321e1f0 (patch)
treef14401f6e7b56d1744a0a1cfbf421ab90d6681f4 /lib/Support/MemoryBuffer.cpp
parentec1f94423034014d4cc63d30aecdca7e30342fe8 (diff)
Add new MemoryBuffer::getMemBufferCopy method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42815 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/MemoryBuffer.cpp')
-rw-r--r--lib/Support/MemoryBuffer.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 0ae5676acc..f8779e122d 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/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