LLVM 22.0.0git
llvm::WritableMemoryBuffer Class Reference

This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying contents. More...

#include "llvm/Support/MemoryBuffer.h"

Inheritance diagram for llvm::WritableMemoryBuffer:
[legend]

Public Member Functions

chargetBufferStart ()
chargetBufferEnd ()
MutableArrayRef< chargetBuffer ()
StringRef getBuffer () const
const chargetBufferEnd () const
const chargetBufferStart () const
Public Member Functions inherited from llvm::MemoryBuffer
 MemoryBuffer (const MemoryBuffer &)=delete
MemoryBufferoperator= (const MemoryBuffer &)=delete
virtual ~MemoryBuffer ()
const chargetBufferStart () const
const chargetBufferEnd () 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.
virtual void dontNeedIfMmap ()
 For read-only MemoryBuffer_MMap, mark the buffer as unused in the near future and the kernel can free resources associated with it.
virtual BufferKind getBufferKind () const =0
 Return information on the memory mechanism used to support the MemoryBuffer.
MemoryBufferRef getMemBufferRef () const

Static Public Member Functions

static LLVM_ABI ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFile (const Twine &Filename, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
static LLVM_ABI ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFileSlice (const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
 Map a subrange of the specified file as a WritableMemoryBuffer.
static LLVM_ABI std::unique_ptr< WritableMemoryBuffergetNewUninitMemBuffer (size_t Size, const Twine &BufferName="", std::optional< Align > Alignment=std::nullopt)
 Allocate a new MemoryBuffer of the specified size that is not initialized.
static LLVM_ABI std::unique_ptr< WritableMemoryBuffergetNewMemBuffer (size_t Size, const Twine &BufferName="")
 Allocate a new zero-initialized MemoryBuffer of the specified size.
Static Public Member Functions inherited from llvm::MemoryBuffer
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile (const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
 Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileAsStream (const Twine &Filename)
 Read all of the specified file into a MemoryBuffer as a stream (i.e.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFileSlice (sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
 Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile (sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
 Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffergetMemBuffer (StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
 Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBuffergetMemBuffer (MemoryBufferRef Ref, bool RequiresNullTerminator=true)
static std::unique_ptr< MemoryBuffergetMemBufferCopy (StringRef InputData, const Twine &BufferName="")
 Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
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 (const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
 Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileSlice (const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
 Map a subrange of the specified file as a MemoryBuffer.

Protected Member Functions

 WritableMemoryBuffer ()=default
Protected Member Functions inherited from llvm::MemoryBuffer
 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.

Additional Inherited Members

Public Types inherited from llvm::MemoryBuffer
enum  BufferKind { MemoryBuffer_Malloc , MemoryBuffer_MMap }
 The kind of memory backing used to support the MemoryBuffer. More...

Detailed Description

This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying contents.

It only supports creation methods that are guaranteed to produce a writable buffer. For example, mapping a file read-only is not supported.

Definition at line 182 of file MemoryBuffer.h.

Constructor & Destructor Documentation

◆ WritableMemoryBuffer()

llvm::WritableMemoryBuffer::WritableMemoryBuffer ( )
protecteddefault

Member Function Documentation

◆ getBuffer() [1/2]

MutableArrayRef< char > llvm::WritableMemoryBuffer::getBuffer ( )
inline

Definition at line 199 of file MemoryBuffer.h.

References getBufferEnd(), and getBufferStart().

◆ getBuffer() [2/2]

StringRef llvm::MemoryBuffer::getBuffer ( ) const
inline

Definition at line 71 of file MemoryBuffer.h.

◆ getBufferEnd() [1/2]

char * llvm::WritableMemoryBuffer::getBufferEnd ( )
inline

Definition at line 196 of file MemoryBuffer.h.

References llvm::MemoryBuffer::getBufferEnd().

Referenced by getBuffer().

◆ getBufferEnd() [2/2]

const char * llvm::MemoryBuffer::getBufferEnd ( ) const
inline

Definition at line 68 of file MemoryBuffer.h.

◆ getBufferStart() [1/2]

char * llvm::WritableMemoryBuffer::getBufferStart ( )
inline

Definition at line 193 of file MemoryBuffer.h.

References llvm::MemoryBuffer::getBufferStart().

Referenced by getBuffer().

◆ getBufferStart() [2/2]

const char * llvm::MemoryBuffer::getBufferStart ( ) const
inline

Definition at line 67 of file MemoryBuffer.h.

◆ getFile()

ErrorOr< std::unique_ptr< WritableMemoryBuffer > > WritableMemoryBuffer::getFile ( const Twine & Filename,
bool IsVolatile = false,
std::optional< Align > Alignment = std::nullopt )
static

Definition at line 289 of file MemoryBuffer.cpp.

References getFileAux().

◆ getFileSlice()

ErrorOr< std::unique_ptr< WritableMemoryBuffer > > WritableMemoryBuffer::getFileSlice ( const Twine & Filename,
uint64_t MapSize,
uint64_t Offset,
bool IsVolatile = false,
std::optional< Align > Alignment = std::nullopt )
static

Map a subrange of the specified file as a WritableMemoryBuffer.

Definition at line 297 of file MemoryBuffer.cpp.

References getFileAux(), and llvm::Offset.

◆ getNewMemBuffer()

std::unique_ptr< WritableMemoryBuffer > WritableMemoryBuffer::getNewMemBuffer ( size_t Size,
const Twine & BufferName = "" )
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 347 of file MemoryBuffer.cpp.

References getNewUninitMemBuffer(), and Size.

Referenced by llvm::objcopy::elf::ASCIIHexWriter::finalize(), llvm::objcopy::elf::BinaryWriter::finalize(), llvm::objcopy::elf::ELFWriter< ELFT >::finalize(), llvm::object::WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(), llvm::objcopy::macho::MachOWriter::write(), and llvm::objcopy::xcoff::XCOFFWriter::write().

◆ getNewUninitMemBuffer()

std::unique_ptr< WritableMemoryBuffer > WritableMemoryBuffer::getNewUninitMemBuffer ( size_t Size,
const Twine & BufferName = "",
std::optional< Align > Alignment = std::nullopt )
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.

Parameters
AlignmentSet to indicate that the buffer should be aligned to at least the specified alignment.

Definition at line 306 of file MemoryBuffer.cpp.

References llvm::alignAddr(), CopyStringRef(), Size, llvm::StringRef::size(), llvm::Twine::toStringRef(), and llvm::Align::value().

Referenced by llvm::object::COFFObjectFile::getHybridObjectView(), getMemBufferCopyImpl(), getNewMemBuffer(), getOpenFileImpl(), and loadBinaryFormat().


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