LLVM
8.0.1
|
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 "llvm/Support/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 IsVolatile=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, bool IsVolatile=false) |
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 IsVolatile=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 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, bool IsVolatile=false) |
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... | |
Static Protected Attributes | |
static constexpr sys::fs::mapped_file_region::mapmode | Mapmode |
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 42 of file MemoryBuffer.h.
The kind of memory backing used to support the MemoryBuffer.
Enumerator | |
---|---|
MemoryBuffer_Malloc | |
MemoryBuffer_MMap |
Definition at line 140 of file MemoryBuffer.h.
|
protecteddefault |
|
delete |
|
virtual |
Definition at line 42 of file MemoryBuffer.cpp.
|
inline |
Definition at line 64 of file MemoryBuffer.h.
References getBufferSize().
Referenced by llvm::vfs::InMemoryFileSystem::addFileNoOwn(), llvm::TGLexer::getLoc(), getMemBufferRef(), isOperator(), llvm::SpecialCaseList::parse(), and llvm::TGLexer::TGLexer().
Definition at line 61 of file MemoryBuffer.h.
Referenced by llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), llvm::WritableMemoryBuffer::getBufferEnd(), llvm::WriteThroughMemoryBuffer::getBufferEnd(), llvm::SourceMgr::GetMessage(), llvm::line_iterator::line_iterator(), and llvm::CodeGenCoverage::parse().
|
inlinevirtual |
Return an identifier for this buffer, typically the filename it was read from.
Reimplemented in llvm::SmallVectorMemoryBuffer.
Definition at line 70 of file MemoryBuffer.h.
References getFile(), getFileAsStream(), getFileOrSTDIN(), getFileSlice(), getMemBuffer(), getMemBufferCopy(), getOpenFile(), getOpenFileSlice(), getSTDIN(), llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile, and llvm::Ref.
Referenced by llvm::vfs::InMemoryFileSystem::addFileNoOwn(), getMemBufferRef(), llvm::SourceMgr::GetMessage(), and llvm::SymbolRemappingReader::read().
|
pure virtual |
Return information on the memory mechanism used to support the MemoryBuffer.
Implemented in llvm::SmallVectorMemoryBuffer.
|
inline |
Definition at line 62 of file MemoryBuffer.h.
Referenced by llvm::FileCheck::CanonicalizeFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), getBuffer(), llvm::TextInstrProfReader::hasFormat(), llvm::RawInstrProfReader< IntPtrT >::hasFormat(), llvm::IndexedInstrProfReader::hasFormat(), and llvm::line_iterator::line_iterator().
Definition at line 60 of file MemoryBuffer.h.
Referenced by llvm::FileCheck::CanonicalizeFile(), llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), llvm::WritableMemoryBuffer::getBufferStart(), llvm::WriteThroughMemoryBuffer::getBufferStart(), llvm::SourceMgr::GetMessage(), llvm::TextInstrProfReader::hasFormat(), llvm::RawInstrProfReader< IntPtrT >::hasFormat(), llvm::IndexedInstrProfReader::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), llvm::line_iterator::line_iterator(), and llvm::CodeGenCoverage::parse().
|
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.
IsVolatile | Set to true to indicate that the contents of the file can change outside the user's control, e.g. when libclang tries to parse while the user is editing/updating the file or if the file is on an NFS. |
Definition at line 230 of file MemoryBuffer.cpp.
References getOpenFileImpl(), and llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile.
Referenced by llvm::SourceMgr::AddIncludeFile(), llvm::LTOCodeGenerator::compileOptimized(), llvm::computeLTOCacheKey(), llvm::createBlockExtractorPass(), llvm::LTOModule::createFromFile(), llvm::SpecialCaseList::createInternal(), llvm::object::ObjectFile::createObjectFile(), llvm::DiffFilesWithTolerance(), ExpandResponseFile(), llvm::object::Archive::Child::getBuffer(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), getFileOrSTDIN(), llvm::unittest::getInputFileDirectory(), llvm::identify_magic(), llvm::LTOModule::isBitcodeFile(), LLVMCreateMemoryBufferWithContentsOfFile(), openFile(), llvm::SymbolRewriter::RewriteMapParser::parse(), parseCHRFilterFiles(), printSymbolizedStackTrace(), llvm::WholeProgramDevirtPass::run(), llvm::runFuzzerOnInputs(), selectJumpTableArmEncoding(), and llvm::TableGenMain().
|
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 519 of file MemoryBuffer.cpp.
References getMemoryBufferForStream(), llvm::sys::fs::OF_None, llvm::sys::fs::openFileForRead(), and llvm::MipsISD::Ret.
Referenced by llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), llvm::sys::getHostCPUName(), and getProcCpuinfoContent().
|
static |
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Definition at line 144 of file MemoryBuffer.cpp.
References getFile(), getSTDIN(), and llvm::Twine::toStringRef().
Referenced by branchDiv(), llvm::object::createBinary(), llvm::createMIRParserFromFile(), llvm::symbolize::LLVMSymbolizer::flush(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), llvm::getModuleSummaryIndexForFile(), llvm::coverage::CoverageMapping::load(), llvm::pdb::loadDataForPDB(), setupMemoryBuffer(), and llvm::TableGenMain().
|
static |
Map a subrange of the specified file as a MemoryBuffer.
Definition at line 155 of file MemoryBuffer.cpp.
References llvm::sys::fs::mapped_file_region::alignment(), llvm::sys::fs::mapped_file_region::const_data(), and llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile.
Referenced by llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), and getBufferIdentifier().
|
static |
Open the specified memory range as a MemoryBuffer.
Note that InputData must be null terminated if RequiresNullTerminator is true.
Definition at line 113 of file MemoryBuffer.cpp.
References llvm::MipsISD::Ret.
Referenced by llvm::vfs::InMemoryFileSystem::addFileNoOwn(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), getMemBuffer(), llvm::NewArchiveMember::getOldMember(), llvm::MIRParserImpl::initializeMachineFunction(), LLVMCreateMemoryBufferWithMemoryRange(), llvm::LTOModule::makeBuffer(), llvm::parseModule(), and llvm::yaml::Scanner::Scanner().
|
static |
Definition at line 121 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 136 of file MemoryBuffer.cpp.
References getMemBufferCopyImpl().
Referenced by llvm::orc::OrcMCJITReplacement::addObjectFile(), EmitDebugSectionImpl(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), isOperator(), LLVMCreateMemoryBufferWithMemoryRangeCopy(), LLVMWriteBitcodeToMemoryBuffer(), llvm::lto::localCache(), llvm::FileCheck::ReadCheckFile(), llvm::orc::OrcMCJITReplacement::setProcessAllSections(), srcMgrDiagHandler(), and llvm::InstrProfWriter::writeBuffer().
MemoryBufferRef MemoryBuffer::getMemBufferRef | ( | ) | const |
Definition at line 530 of file MemoryBuffer.cpp.
References llvm::Data, getBuffer(), and getBufferIdentifier().
Referenced by llvm::LTOModule::getProducerString(), llvm::LTOModule::isBitcodeForTarget(), and llvm::orc::SimpleCompiler::operator()().
|
static |
Given an already-open file descriptor, read the file and return a MemoryBuffer.
IsVolatile | Set to true to indicate that the contents of the file can change outside the user's control, e.g. when libclang tries to parse while the user is editing/updating the file or if the file is on an NFS. |
Definition at line 494 of file MemoryBuffer.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile.
Referenced by llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), llvm::NewArchiveMember::getFile(), llvm::lto::localCache(), and pathHasTraversal().
|
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 501 of file MemoryBuffer.cpp.
References assert(), and llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile.
Referenced by llvm::LTOModule::createFromOpenFileSlice(), llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), and getBufferIdentifier().
|
static |
Read all of stdin into a file buffer, and return it.
Definition at line 508 of file MemoryBuffer.cpp.
References llvm::sys::ChangeStdinToBinary(), and getMemoryBufferForStream().
Referenced by llvm::WritableMemoryBuffer::getBuffer(), llvm::WriteThroughMemoryBuffer::getBuffer(), getBufferIdentifier(), 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 46 of file MemoryBuffer.cpp.
References assert().
Referenced by llvm::SmallVectorMemoryBuffer::SmallVectorMemoryBuffer().
|
delete |
|
staticprotected |
Definition at line 52 of file MemoryBuffer.h.