|
LLVM
4.0.0
|
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. More...
#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 | |
| MemoryBuffer (const MemoryBuffer &)=delete | |
| MemoryBuffer & | operator= (const MemoryBuffer &)=delete |
| virtual | ~MemoryBuffer () |
| const char * | getBufferStart () const |
| const char * | getBufferEnd () const |
| size_t | getBufferSize () const |
| StringRef | getBuffer () const |
| virtual StringRef | getBufferIdentifier () const |
| Return an identifier for this buffer, typically the filename it was read from. More... | |
| virtual BufferKind | getBufferKind () const =0 |
| Return information on the memory mechanism used to support the MemoryBuffer. More... | |
| MemoryBufferRef | getMemBufferRef () const |
Static Public Member Functions | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getFile (const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false) |
| Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null. More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getFileAsStream (const Twine &Filename) |
| Read all of the specified file into a MemoryBuffer as a stream (i.e. More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getOpenFileSlice (int FD, const Twine &Filename, uint64_t MapSize, int64_t Offset) |
| Given an already-open file descriptor, map some slice of it into a MemoryBuffer. More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getOpenFile (int FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatileSize=false) |
| Given an already-open file descriptor, read the file and return a MemoryBuffer. More... | |
| static std::unique_ptr < MemoryBuffer > | getMemBuffer (StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true) |
| Open the specified memory range as a MemoryBuffer. More... | |
| static std::unique_ptr < MemoryBuffer > | getMemBuffer (MemoryBufferRef Ref, bool RequiresNullTerminator=true) |
| static std::unique_ptr < MemoryBuffer > | getMemBufferCopy (StringRef InputData, const Twine &BufferName="") |
| Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it. More... | |
| static std::unique_ptr < MemoryBuffer > | getNewMemBuffer (size_t Size, StringRef BufferName="") |
| Allocate a new zero-initialized MemoryBuffer of the specified size. More... | |
| static std::unique_ptr < MemoryBuffer > | getNewUninitMemBuffer (size_t Size, const Twine &BufferName="") |
| Allocate a new MemoryBuffer of the specified size that is not initialized. More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getSTDIN () |
| Read all of stdin into a file buffer, and return it. More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getFileOrSTDIN (const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true) |
| Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-". More... | |
| static ErrorOr < std::unique_ptr < MemoryBuffer > > | getFileSlice (const Twine &Filename, uint64_t MapSize, uint64_t Offset) |
| Map a subrange of the specified file as a MemoryBuffer. More... | |
Protected Member Functions | |
| MemoryBuffer ()=default | |
| void | init (const char *BufStart, const char *BufEnd, bool RequiresNullTerminator) |
| init - Initialize this MemoryBuffer as a reference to externally allocated memory, memory that we know is already null terminated. More... | |
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 40 of file MemoryBuffer.h.
The kind of memory backing used to support the MemoryBuffer.
| Enumerator | |
|---|---|
| MemoryBuffer_Malloc | |
| MemoryBuffer_MMap | |
Definition at line 146 of file MemoryBuffer.h.
|
protecteddefault |
|
delete |
|
virtual |
Definition at line 41 of file MemoryBuffer.cpp.
|
inline |
Definition at line 59 of file MemoryBuffer.h.
References getBufferSize().
Referenced by getMemBufferRef(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readGCDAFormat(), llvm::GCOVBuffer::readGCNOFormat(), llvm::GCOVBuffer::readGCOVVersion(), llvm::GCOVBuffer::readInt(), llvm::GCOVBuffer::readLineTag(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), llvm::GCOVBuffer::readString(), llvm::TGLexer::TGLexer(), and writeGeneratedObject().
|
inline |
Definition at line 56 of file MemoryBuffer.h.
Referenced by llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::SourceMgr::GetMessage(), and llvm::line_iterator::line_iterator().
|
inlinevirtual |
Return an identifier for this buffer, typically the filename it was read from.
Reimplemented in llvm::ObjectMemoryBuffer, and llvm::ObjectMemoryBuffer.
Definition at line 65 of file MemoryBuffer.h.
Referenced by getMemBufferRef(), and llvm::SourceMgr::GetMessage().
|
pure virtual |
Return information on the memory mechanism used to support the MemoryBuffer.
Implemented in llvm::ObjectMemoryBuffer, and llvm::ObjectMemoryBuffer.
|
inline |
Definition at line 57 of file MemoryBuffer.h.
Referenced by llvm::DiffFilesWithTolerance(), ExpandResponseFile(), getBuffer(), llvm::TextInstrProfReader::hasFormat(), llvm::RawInstrProfReader< IntPtrT >::hasFormat(), llvm::IndexedInstrProfReader::hasFormat(), and llvm::line_iterator::line_iterator().
|
inline |
Definition at line 55 of file MemoryBuffer.h.
Referenced by llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::SourceMgr::getLineAndColumn(), llvm::SourceMgr::GetMessage(), llvm::TextInstrProfReader::hasFormat(), llvm::RawInstrProfReader< IntPtrT >::hasFormat(), llvm::sampleprof::SampleProfileReaderBinary::hasFormat(), llvm::IndexedInstrProfReader::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), and llvm::line_iterator::line_iterator().
|
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.
| IsVolatileSize | Set 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 256 of file MemoryBuffer.cpp.
References getFileAux().
Referenced by llvm::SourceMgr::AddIncludeFile(), commitEntry(), llvm::LTOCodeGenerator::compileOptimized(), computeCacheKey(), llvm::SpecialCaseList::create(), llvm::LTOModule::createFromFile(), llvm::createMIRParserFromFile(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::object::Archive::Child::getBuffer(), getFileOrSTDIN(), llvm::LTOModule::isBitcodeFile(), LLVMCreateMemoryBufferWithContentsOfFile(), llvm::SymbolRewriter::RewriteMapParser::parse(), and printSymbolizedStackTrace().
|
static |
Read all of the specified file into a MemoryBuffer as a stream (i.e.
until EOF reached). This is useful for special files that look like a regular file but have 0 size (e.g. /proc/cpuinfo on Linux).
Definition at line 442 of file MemoryBuffer.cpp.
References getMemoryBufferForStream(), llvm::sys::fs::openFileForRead(), and llvm::MipsISD::Ret.
|
static |
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Definition at line 169 of file MemoryBuffer.cpp.
References getFile(), getSTDIN(), and llvm::Twine::toStringRef().
Referenced by llvm::object::createBinary(), llvm::pdb::RawSession::createFromPdb(), llvm::getLazyIRFileModule(), llvm::getModuleSummaryIndexForFile(), llvm::coverage::CoverageMapping::load(), llvm::parseAssemblyFile(), llvm::parseIRFile(), setupMemoryBuffer(), and llvm::TableGenMain().
|
static |
Map a subrange of the specified file as a MemoryBuffer.
Definition at line 180 of file MemoryBuffer.cpp.
References getFileAux().
|
static |
Open the specified memory range as a MemoryBuffer.
Note that InputData must be null terminated if RequiresNullTerminator is true.
Definition at line 109 of file MemoryBuffer.cpp.
References llvm::MipsISD::Ret.
Referenced by llvm::yaml::Output::blockScalarString(), llvm::ModuleSymbolTable::CollectAsmSymbols(), getMemBuffer(), llvm::NewArchiveMember::getOldMember(), llvm::MIRParserImpl::initializeMachineFunction(), LLVMCreateMemoryBufferWithMemoryRange(), llvm::LTOModule::makeBuffer(), llvm::parseAssemblyInto(), llvm::parseConstantValue(), llvm::parseType(), and llvm::parseTypeAtBeginning().
|
static |
Definition at line 117 of file MemoryBuffer.cpp.
References llvm::MemoryBufferRef::getBuffer(), llvm::MemoryBufferRef::getBufferIdentifier(), and getMemBuffer().
|
static |
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
InputData does not have to be null terminated.
Definition at line 123 of file MemoryBuffer.cpp.
References llvm::StringRef::data(), getNewUninitMemBuffer(), and llvm::StringRef::size().
Referenced by getMemoryBufferForStream(), LLVMCreateMemoryBufferWithMemoryRangeCopy(), LLVMWriteBitcodeToMemoryBuffer(), and llvm::InstrProfWriter::writeBuffer().
| MemoryBufferRef MemoryBuffer::getMemBufferRef | ( | ) | const |
Definition at line 453 of file MemoryBuffer.cpp.
References getBuffer(), and getBufferIdentifier().
Referenced by llvm::LTOModule::getProducerString(), and llvm::LTOModule::isBitcodeForTarget().
|
static |
Allocate a new zero-initialized MemoryBuffer of the specified size.
Note that the caller need not initialize the memory allocated by this method. The memory is owned by the MemoryBuffer object.
Definition at line 160 of file MemoryBuffer.cpp.
References getNewUninitMemBuffer(), and SB.
|
static |
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 134 of file MemoryBuffer.cpp.
References llvm::alignTo(), CopyStringRef(), llvm::MipsISD::Ret, llvm::StringRef::size(), and llvm::Twine::toStringRef().
Referenced by getMemBufferCopy(), getNewMemBuffer(), and getOpenFileImpl().
|
static |
Given an already-open file descriptor, read the file and return a MemoryBuffer.
| IsVolatileSize | Set 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 417 of file MemoryBuffer.cpp.
References getOpenFileImpl().
Referenced by llvm::NewArchiveMember::getFile().
|
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 424 of file MemoryBuffer.cpp.
References assert(), and getOpenFileImpl().
Referenced by llvm::LTOModule::createFromOpenFileSlice().
|
static |
Read all of stdin into a file buffer, and return it.
Definition at line 431 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 45 of file MemoryBuffer.cpp.
References assert().
Referenced by llvm::ObjectMemoryBuffer::ObjectMemoryBuffer().
|
delete |
1.8.6