Add new MemoryBuffer::getMemBufferCopy method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42815 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-10-09 21:46:38 +00:00
parent ec1f944230
commit 3daae2701b
2 changed files with 21 additions and 2 deletions

View 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

View 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