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:41

Member Variables

protected static const sys::fs::mapped_file_region::mapmode Mapmode = sys::fs::mapped_file_region::readonly

Method Overview

  • protected MemoryBuffer()
  • public MemoryBuffer(const llvm::MemoryBuffer &)
  • 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, int64_t FileSize = -1, 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, int64_t FileSize = -1, 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:46

MemoryBuffer(const llvm::MemoryBuffer&)

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

Parameters

const llvm::MemoryBuffer&

llvm::StringRef getBuffer() const

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

const char* getBufferEnd() const

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

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:69

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:146

size_t getBufferSize() const

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

const char* getBufferStart() const

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

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

Description

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.

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

Parameters

const llvm::Twine& Filename
int64_t FileSize = -1
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:87

Parameters

const llvm::Twine& Filename

static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileOrSTDIN(const llvm::Twine& Filename,
               int64_t FileSize = -1,
               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:126

Parameters

const llvm::Twine& Filename
int64_t FileSize = -1
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:131

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:109

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:113

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:118

Parameters

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

llvm::MemoryBufferRef getMemBufferRef() const

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

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:103

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:93

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:121

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

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

Parameters

const char* BufStart
const char* BufEnd
bool RequiresNullTerminator

virtual ~MemoryBuffer()

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