14 #ifndef LLVM_SUPPORT_MEMORYBUFFER_H
15 #define LLVM_SUPPORT_MEMORYBUFFER_H
20 #include "llvm/Support/DataTypes.h"
25 class MemoryBufferRef;
38 const char *BufferStart;
39 const char *BufferEnd;
45 void init(
const char *BufStart,
const char *BufEnd,
46 bool RequiresNullTerminator);
61 return "Unknown buffer";
74 bool RequiresNullTerminator =
true,
bool IsVolatileSize =
false);
91 bool RequiresNullTerminator =
true,
bool IsVolatileSize =
false);
95 static std::unique_ptr<MemoryBuffer>
97 bool RequiresNullTerminator =
true);
99 static std::unique_ptr<MemoryBuffer>
104 static std::unique_ptr<MemoryBuffer>
110 static std::unique_ptr<MemoryBuffer>
116 static std::unique_ptr<MemoryBuffer>
155 : Buffer(Buffer), Identifier(Identifier) {}
MemoryBufferRef getMemBufferRef() const
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.
Represents either an error or a value T.
size_t size() const
size - Get the string size.
const char * getBufferStart() const
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
Used to pass regions of memory through LLVM interfaces.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
StringRef getBuffer() const
const char * getBufferStart() const
static std::unique_ptr< MemoryBuffer > getNewUninitMemBuffer(size_t Size, const Twine &BufferName="")
Allocate a new MemoryBuffer of the specified size that is not initialized.
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.
static std::unique_ptr< MemoryBuffer > getNewMemBuffer(size_t Size, StringRef BufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
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.
virtual const char * getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
virtual BufferKind getBufferKind() const =0
Return information on the memory mechanism used to support the MemoryBuffer.
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
const char * getBufferEnd() const
size_t getBufferSize() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
StringRef getBuffer() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
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...
size_t getBufferSize() const
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.
BufferKind
The kind of memory backing used to support the MemoryBuffer.
const char * getBufferEnd() const
Provides ErrorOr<T> smart pointer.
StringRef getBufferIdentifier() const
MemoryBufferRef(StringRef Buffer, StringRef Identifier)
StringRef - Represent a constant reference to a string, i.e.
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.