LLVM API Documentation
#include <MemoryBuffer.h>
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 error_code | getFile (Twine Filename, OwningPtr< MemoryBuffer > &result, int64_t FileSize=-1, bool RequiresNullTerminator=true) |
static error_code | getOpenFileSlice (int FD, const char *Filename, OwningPtr< MemoryBuffer > &Result, uint64_t MapSize, int64_t Offset) |
static error_code | getOpenFile (int FD, const char *Filename, OwningPtr< MemoryBuffer > &Result, uint64_t FileSize, bool RequiresNullTerminator=true) |
static MemoryBuffer * | getMemBuffer (StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true) |
static MemoryBuffer * | getMemBufferCopy (StringRef InputData, StringRef BufferName="") |
static MemoryBuffer * | getNewMemBuffer (size_t Size, StringRef BufferName="") |
static MemoryBuffer * | getNewUninitMemBuffer (size_t Size, StringRef BufferName="") |
static error_code | getSTDIN (OwningPtr< MemoryBuffer > &result) |
static error_code | getFileOrSTDIN (StringRef Filename, OwningPtr< MemoryBuffer > &result, int64_t FileSize=-1) |
Protected Member Functions | |
MemoryBuffer () | |
void | init (const char *BufStart, const char *BufEnd, bool RequiresNullTerminator) |
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 38 of file MemoryBuffer.h.
The kind of memory backing used to support the MemoryBuffer.
Enumerator | |
---|---|
MemoryBuffer_Malloc | |
MemoryBuffer_MMap |
Definition at line 129 of file MemoryBuffer.h.
|
inlineprotected |
Definition at line 45 of file MemoryBuffer.h.
|
virtual |
Definition at line 50 of file MemoryBuffer.cpp.
|
inline |
Definition at line 55 of file MemoryBuffer.h.
References getBufferSize().
Referenced by llvm::object::createBinary(), llvm::object::ObjectFile::createMachOObjectFile(), llvm::object::ObjectFile::createObjectFile(), llvm::DWARFContextInMemory::DWARFContextInMemory(), llvm::object::Binary::getData(), llvm::FileInfo::print(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readGCOVFormat(), llvm::GCOVBuffer::readInt(), llvm::GCOVBuffer::readLineTag(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), and llvm::GCOVBuffer::readString().
|
inline |
Definition at line 52 of file MemoryBuffer.h.
Referenced by llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::getLazyIRModule(), llvm::SourceMgr::GetMessage(), llvm::AsmLexer::LexUntilEndOfLine(), llvm::AsmLexer::LexUntilEndOfStatement(), llvm::ParseIR(), and llvm::yaml::Scanner::Scanner().
|
inlinevirtual |
getBufferIdentifier - Return an identifier for this buffer, typically the filename it was read from.
Definition at line 61 of file MemoryBuffer.h.
Referenced by llvm::LLLexer::getFilename(), llvm::object::Binary::getFileName(), llvm::getLazyBitcodeModule(), llvm::getLazyIRModule(), llvm::SourceMgr::GetMessage(), llvm::MCContext::MCContext(), llvm::ParseAssembly(), and llvm::ParseIR().
|
pure virtual |
Return information on the memory mechanism used to support the MemoryBuffer.
|
inline |
Definition at line 53 of file MemoryBuffer.h.
Referenced by llvm::object::Archive::Archive(), llvm::object::Archive::begin_children(), LTOCodeGenerator::compile(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), llvm::object::ELFFile< ELFT >::ELFFile(), ExpandResponseFile(), getBuffer(), llvm::object::getElfArchType(), and llvm::object::MachOUniversalBinary::MachOUniversalBinary().
|
inline |
Definition at line 51 of file MemoryBuffer.h.
Referenced by llvm::object::Archive::Archive(), llvm::object::ObjectFile::base(), llvm::object::Archive::begin_children(), LTOCodeGenerator::compile(), llvm::zlib::compress(), llvm::object::ObjectFile::createELFObjectFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::object::getElfArchType(), llvm::getLazyIRModule(), llvm::SourceMgr::getLineAndColumn(), getMemBufferCopy(), llvm::SourceMgr::GetMessage(), getNewMemBuffer(), getOpenFileImpl(), llvm::LLLexer::LLLexer(), llvm::ParseIR(), llvm::yaml::Scanner::Scanner(), llvm::AsmLexer::setBuffer(), llvm::TGLexer::TGLexer(), and llvm::zlib::uncompress().
|
static |
getFile - 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.
Definition at line 245 of file MemoryBuffer.cpp.
References llvm::StringRef::data(), getFileAux(), and llvm::Twine::toNullTerminatedStringRef().
Referenced by llvm::SourceMgr::AddIncludeFile(), llvm::SpecialCaseList::create(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), getFileOrSTDIN(), and LLVMCreateMemoryBufferWithContentsOfFile().
|
static |
getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-". If an error occurs, this returns null and sets ec.
getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-". If an error occurs, this returns null and fills in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN) returns an empty buffer.
Definition at line 167 of file MemoryBuffer.cpp.
References getFile(), and getSTDIN().
Referenced by llvm::object::createBinary(), llvm::getLazyIRFileModule(), llvm::ParseAssemblyFile(), llvm::ParseIRFile(), llvm::FileInfo::print(), and llvm::TableGenMain().
|
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 107 of file MemoryBuffer.cpp.
Referenced by llvm::ObjectBufferStream::flush(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsObjectFile(), llvm::ObjectBuffer::getMemBuffer(), llvm::object::Archive::Child::getMemoryBuffer(), LLVMCreateMemoryBufferWithMemoryRange(), llvm::ParseAssemblyString(), and llvm::yaml::Scanner::Scanner().
|
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 117 of file MemoryBuffer.cpp.
References llvm::StringRef::data(), getBufferStart(), getNewUninitMemBuffer(), llvm::Intrinsic::memcpy, and llvm::StringRef::size().
Referenced by llvm::zlib::compress(), getMemoryBufferForStream(), LLVMCreateMemoryBufferWithMemoryRangeCopy(), and llvm::zlib::uncompress().
|
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 155 of file MemoryBuffer.cpp.
References getBufferStart(), getNewUninitMemBuffer(), and llvm::Intrinsic::memset.
|
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 130 of file MemoryBuffer.cpp.
References CopyStringRef(), llvm::RoundUpToAlignment(), and llvm::StringRef::size().
Referenced by getMemBufferCopy(), getNewMemBuffer(), and getOpenFileImpl().
|
static |
Given an already-open file descriptor, read the file and return a MemoryBuffer.
Definition at line 406 of file MemoryBuffer.cpp.
References getOpenFileImpl().
|
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.
Definition at line 414 of file MemoryBuffer.cpp.
References getOpenFileImpl().
|
static |
getSTDIN - Read all of stdin into a file buffer, and return it. If an error occurs, this returns null and sets ec.
Definition at line 424 of file MemoryBuffer.cpp.
References llvm::sys::ChangeStdinToBinary(), and getMemoryBufferForStream().
Referenced by getFileOrSTDIN(), and LLVMCreateMemoryBufferWithSTDIN().
|
protected |
init - Initialize this MemoryBuffer as a reference to externally allocated memory, memory that we know is already null terminated.
Definition at line 54 of file MemoryBuffer.cpp.