class MemoryBuffer

Declaration

class MemoryBuffer { /* full declaration omitted */ };

Description

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.

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:50

Member Variables

private const char* BufferStart
private const char* BufferEnd

Method Overview

  • protected MemoryBuffer()
  • public MemoryBuffer(const llvm::MemoryBuffer &)
  • public virtual void dontNeedIfMmap()
  • public llvm::StringRef getBuffer() const
  • public const char * getBufferEnd() const
  • public virtual llvm::StringRef getBufferIdentifier() const
  • public virtual llvm::MemoryBuffer::BufferKind getBufferKind() const
  • public size_t getBufferSize() const
  • public const char * getBufferStart() const
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getFile(const llvm::Twine & Filename, bool IsText = false, bool RequiresNullTerminator = true, bool IsVolatile = false)
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getFileAsStream(const llvm::Twine & Filename)
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getFileOrSTDIN(const llvm::Twine & Filename, bool IsText = false, bool RequiresNullTerminator = true)
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getFileSlice(const llvm::Twine & Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile = false)
  • public static std::unique_ptr<MemoryBuffer> getMemBuffer(llvm::StringRef InputData, llvm::StringRef BufferName = "", bool RequiresNullTerminator = true)
  • public static std::unique_ptr<MemoryBuffer> getMemBuffer(llvm::MemoryBufferRef Ref, bool RequiresNullTerminator = true)
  • public static std::unique_ptr<MemoryBuffer> getMemBufferCopy(llvm::StringRef InputData, const llvm::Twine & BufferName = "")
  • public llvm::MemoryBufferRef getMemBufferRef() const
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getOpenFile(sys::fs::file_t FD, const llvm::Twine & Filename, uint64_t FileSize, bool RequiresNullTerminator = true, bool IsVolatile = false)
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getOpenFileSlice(sys::fs::file_t FD, const llvm::Twine & Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile = false)
  • public static ErrorOr<std::unique_ptr<MemoryBuffer>> getSTDIN()
  • protected void init(const char * BufStart, const char * BufEnd, bool RequiresNullTerminator)
  • public virtual ~MemoryBuffer()

Methods

MemoryBuffer()

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:55

MemoryBuffer(const llvm::MemoryBuffer&)

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:61

Parameters

const llvm::MemoryBuffer&

virtual void dontNeedIfMmap()

Description

For read-only MemoryBuffer_MMap, mark the buffer as unused in the near future and the kernel can free resources associated with it. Further access is supported but may be expensive. This calls madvise(MADV_DONTNEED) on read-only file mappings on *NIX systems. This function should not be called on a writable buffer.

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:82

llvm::StringRef getBuffer() const

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:69

const char* getBufferEnd() const

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:66

virtual llvm::StringRef getBufferIdentifier()
    const

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:75

virtual llvm::MemoryBuffer::BufferKind
getBufferKind() const

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:160

size_t getBufferSize() const

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:67

const char* getBufferStart() const

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:65

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFile(const llvm::Twine& Filename,
        bool IsText = false,
        bool RequiresNullTerminator = true,
        bool IsVolatile = false)

Description

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:94

Parameters

const llvm::Twine& Filename
bool IsText = false
Set to true to indicate that the file should be read in text mode.
bool RequiresNullTerminator = true
bool IsVolatile = false
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.

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileAsStream(const llvm::Twine& Filename)

Description

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).

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:101

Parameters

const llvm::Twine& Filename

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileOrSTDIN(const llvm::Twine& Filename,
               bool IsText = false,
               bool RequiresNullTerminator = true)

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:140

Parameters

const llvm::Twine& Filename
bool IsText = false
bool RequiresNullTerminator = true

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileSlice(const llvm::Twine& Filename,
             uint64_t MapSize,
             uint64_t Offset,
             bool IsVolatile = false)

Description

Map a subrange of the specified file as a MemoryBuffer.

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:145

Parameters

const llvm::Twine& Filename
uint64_t MapSize
uint64_t Offset
bool IsVolatile = false

static std::unique_ptr<MemoryBuffer> getMemBuffer(
    llvm::StringRef InputData,
    llvm::StringRef BufferName = "",
    bool RequiresNullTerminator = true)

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:123

Parameters

llvm::StringRef InputData
llvm::StringRef BufferName = ""
bool RequiresNullTerminator = true

static std::unique_ptr<MemoryBuffer> getMemBuffer(
    llvm::MemoryBufferRef Ref,
    bool RequiresNullTerminator = true)

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:127

Parameters

llvm::MemoryBufferRef Ref
bool RequiresNullTerminator = true

static std::unique_ptr<MemoryBuffer>
getMemBufferCopy(
    llvm::StringRef InputData,
    const llvm::Twine& BufferName = "")

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:132

Parameters

llvm::StringRef InputData
const llvm::Twine& BufferName = ""

llvm::MemoryBufferRef getMemBufferRef() const

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:162

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getOpenFile(sys::fs::file_t FD,
            const llvm::Twine& Filename,
            uint64_t FileSize,
            bool RequiresNullTerminator = true,
            bool IsVolatile = false)

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:117

Parameters

sys::fs::file_t FD
const llvm::Twine& Filename
uint64_t FileSize
bool RequiresNullTerminator = true
bool IsVolatile = false
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.

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getOpenFileSlice(sys::fs::file_t FD,
                 const llvm::Twine& Filename,
                 uint64_t MapSize,
                 int64_t Offset,
                 bool IsVolatile = false)

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:107

Parameters

sys::fs::file_t FD
const llvm::Twine& Filename
uint64_t MapSize
int64_t Offset
bool IsVolatile = false

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

Description

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:135

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

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:57

Parameters

const char* BufStart
const char* BufEnd
bool RequiresNullTerminator

virtual ~MemoryBuffer()

Declared at: llvm/include/llvm/Support/MemoryBuffer.h:63