LLVM API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
llvm::MemoryBuffer Class Reference

#include <MemoryBuffer.h>

List of all members.

Public Types

enum  BufferKind { MemoryBuffer_Malloc, MemoryBuffer_MMap }
 The kind of memory backing used to support the MemoryBuffer. More...

Public Member Functions

virtual ~MemoryBuffer ()
const char * getBufferStart () const
const char * getBufferEnd () const
size_t getBufferSize () const
StringRef getBuffer () const
virtual const char * getBufferIdentifier () const
virtual BufferKind getBufferKind () const =0

Static Public Member Functions

static ErrorOr
< std::unique_ptr
< MemoryBuffer > > 
getFile (Twine Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
static ErrorOr
< std::unique_ptr
< MemoryBuffer > > 
getOpenFileSlice (int FD, const char *Filename, uint64_t MapSize, int64_t Offset, bool IsVolatileSize=false)
static ErrorOr
< std::unique_ptr
< MemoryBuffer > > 
getOpenFile (int FD, const char *Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
static MemoryBuffergetMemBuffer (StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
static MemoryBuffergetMemBufferCopy (StringRef InputData, StringRef BufferName="")
static MemoryBuffergetNewMemBuffer (size_t Size, StringRef BufferName="")
static MemoryBuffergetNewUninitMemBuffer (size_t Size, StringRef BufferName="")
static ErrorOr
< std::unique_ptr
< MemoryBuffer > > 
getSTDIN ()
 Read all of stdin into a file buffer, and return it.
static ErrorOr
< std::unique_ptr
< MemoryBuffer > > 
getFileOrSTDIN (StringRef Filename, int64_t FileSize=-1)

Protected Member Functions

 MemoryBuffer ()
void init (const char *BufStart, const char *BufEnd, bool RequiresNullTerminator)

Detailed Description

MemoryBuffer - This interface provides simple read-only access to a block of memory, and provides simple methods for reading files and standard input into a memory buffer. In addition to basic access to the characters in the file, this interface guarantees you can read one character past the end of the file, and that this character will read as '\0'.

The '\0' guarantee is needed to support an optimization -- it's intended to be more efficient for clients which are reading all the data to stop reading when they encounter a '\0' than to continually check the file position to see if it has reached the end of the file.

Definition at line 37 of file MemoryBuffer.h.


Member Enumeration Documentation

The kind of memory backing used to support the MemoryBuffer.

Enumerator:
MemoryBuffer_Malloc 
MemoryBuffer_MMap 

Definition at line 135 of file MemoryBuffer.h.


Constructor & Destructor Documentation

llvm::MemoryBuffer::MemoryBuffer ( ) [inline, protected]

Definition at line 44 of file MemoryBuffer.h.

Definition at line 42 of file MemoryBuffer.cpp.


Member Function Documentation

const char* llvm::MemoryBuffer::getBufferEnd ( ) const [inline]
virtual const char* llvm::MemoryBuffer::getBufferIdentifier ( ) const [inline, virtual]

getBufferIdentifier - Return an identifier for this buffer, typically the filename it was read from.

Definition at line 60 of file MemoryBuffer.h.

Referenced by llvm::LLLexer::getFilename(), llvm::getLazyBitcodeModule(), getLazyIRModule(), llvm::SourceMgr::GetMessage(), llvm::ParseAssembly(), and llvm::ParseIR().

virtual BufferKind llvm::MemoryBuffer::getBufferKind ( ) const [pure virtual]

Return information on the memory mechanism used to support the MemoryBuffer.

size_t llvm::MemoryBuffer::getBufferSize ( ) const [inline]
const char* llvm::MemoryBuffer::getBufferStart ( ) const [inline]
ErrorOr< std::unique_ptr< MemoryBuffer > > MemoryBuffer::getFile ( Twine  Filename,
int64_t  FileSize = -1,
bool  RequiresNullTerminator = true,
bool  IsVolatileSize = false 
) [static]

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null. If FileSize is specified, this means that the client knows that the file exists and that it has the specified size.

Parameters:
IsVolatileSizeSet to true to indicate that the file size may be changing, e.g. when libclang tries to parse while the user is editing/updating the file.

Definition at line 234 of file MemoryBuffer.cpp.

References llvm::StringRef::data(), getFileAux(), and llvm::Twine::toNullTerminatedStringRef().

Referenced by llvm::SourceMgr::AddIncludeFile(), llvm::LTOCodeGenerator::compile(), llvm::SpecialCaseList::create(), llvm::LTOModule::createFromFile(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), getFileOrSTDIN(), and LLVMCreateMemoryBufferWithContentsOfFile().

ErrorOr< std::unique_ptr< MemoryBuffer > > MemoryBuffer::getFileOrSTDIN ( StringRef  Filename,
int64_t  FileSize = -1 
) [static]

Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".

Definition at line 156 of file MemoryBuffer.cpp.

References getFile(), and getSTDIN().

Referenced by llvm::object::createBinary(), llvm::getLazyIRFileModule(), llvm::ParseAssemblyFile(), llvm::ParseIRFile(), setupMemoryBuffer(), and llvm::TableGenMain().

MemoryBuffer * MemoryBuffer::getMemBuffer ( StringRef  InputData,
StringRef  BufferName = "",
bool  RequiresNullTerminator = true 
) [static]

getMemBuffer - Open the specified memory range as a MemoryBuffer. Note that InputData must be null terminated if RequiresNullTerminator is true.

getMemBuffer - Open the specified memory range as a MemoryBuffer. Note that InputData must be a null terminated if RequiresNullTerminator is true!

Definition at line 99 of file MemoryBuffer.cpp.

Referenced by llvm::RuntimeDyldELF::createObjectImageFromFile(), llvm::ObjectBufferStream::flush(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsArchive(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsObjectFile(), llvm::object::Archive::Child::getMemoryBuffer(), llvm::object::IRObjectFile::IRObjectFile(), LLVMCreateMemoryBufferWithMemoryRange(), llvm::LTOModule::makeBuffer(), llvm::ParseAssemblyString(), llvm::ParseIR(), and llvm::yaml::Scanner::Scanner().

MemoryBuffer * MemoryBuffer::getMemBufferCopy ( StringRef  InputData,
StringRef  BufferName = "" 
) [static]

getMemBufferCopy - Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it. InputData does not have to be null terminated.

getMemBufferCopy - Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it. This has no requirements on EndPtr[0].

Definition at line 109 of file MemoryBuffer.cpp.

References llvm::StringRef::data(), getBufferStart(), getNewUninitMemBuffer(), llvm::LibFunc::memcpy, and llvm::StringRef::size().

Referenced by getMemoryBufferForStream(), and LLVMCreateMemoryBufferWithMemoryRangeCopy().

MemoryBuffer * MemoryBuffer::getNewMemBuffer ( size_t  Size,
StringRef  BufferName = "" 
) [static]

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 the MemoryBuffer object.

Definition at line 148 of file MemoryBuffer.cpp.

References getBufferStart(), getNewUninitMemBuffer(), and llvm::LibFunc::memset.

MemoryBuffer * MemoryBuffer::getNewUninitMemBuffer ( size_t  Size,
StringRef  BufferName = "" 
) [static]

getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size that is not initialized. Note that the caller should initialize the memory allocated by this method. The memory is owned by the MemoryBuffer object.

Definition at line 122 of file MemoryBuffer.cpp.

References CopyStringRef(), operator new(), llvm::RoundUpToAlignment(), and llvm::StringRef::size().

Referenced by getMemBufferCopy(), getNewMemBuffer(), and getOpenFileImpl().

ErrorOr< std::unique_ptr< MemoryBuffer > > MemoryBuffer::getOpenFile ( int  FD,
const char *  Filename,
uint64_t  FileSize,
bool  RequiresNullTerminator = true,
bool  IsVolatileSize = false 
) [static]

Given an already-open file descriptor, read the file and return a MemoryBuffer.

Parameters:
IsVolatileSizeSet to true to indicate that the file size may be changing, e.g. when libclang tries to parse while the user is editing/updating the file.

Definition at line 390 of file MemoryBuffer.cpp.

References getOpenFileImpl().

ErrorOr< std::unique_ptr< MemoryBuffer > > MemoryBuffer::getOpenFileSlice ( int  FD,
const char *  Filename,
uint64_t  MapSize,
int64_t  Offset,
bool  IsVolatileSize = false 
) [static]

Given an already-open file descriptor, map some slice of it into a MemoryBuffer. The slice is specified by an Offset and MapSize. Since this is in the middle of a file, the buffer is not null terminated.

Parameters:
IsVolatileSizeSet to true to indicate that the file size may be changing, e.g. when libclang tries to parse while the user is editing/updating the file.

Definition at line 397 of file MemoryBuffer.cpp.

References getOpenFileImpl().

Referenced by llvm::LTOModule::createFromOpenFileSlice().

ErrorOr< std::unique_ptr< MemoryBuffer > > MemoryBuffer::getSTDIN ( ) [static]

Read all of stdin into a file buffer, and return it.

Definition at line 403 of file MemoryBuffer.cpp.

References llvm::sys::ChangeStdinToBinary(), and getMemoryBufferForStream().

Referenced by getFileOrSTDIN(), and LLVMCreateMemoryBufferWithSTDIN().

void MemoryBuffer::init ( const char *  BufStart,
const char *  BufEnd,
bool  RequiresNullTerminator 
) [protected]

init - Initialize this MemoryBuffer as a reference to externally allocated memory, memory that we know is already null terminated.

Definition at line 46 of file MemoryBuffer.cpp.


The documentation for this class was generated from the following files: