LLVM: include/llvm/Support/MemoryBuffer.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
14#define LLVM_SUPPORT_MEMORYBUFFER_H
15
25#include
26#include
27#include
28
29namespace llvm {
30namespace sys {
31namespace fs {
32
33#if defined(_WIN32)
34
36#else
38#endif
39}
40}
41
42
43
44
45
46
47
48
49
50
51
53 const char *BufferStart;
54 const char *BufferEnd;
55
56protected:
58
59 void init(const char *BufStart, const char *BufEnd,
60 bool RequiresNullTerminator);
61
62public:
66
68 const char *getBufferEnd() const { return BufferEnd; }
69 size_t getBufferSize() const { return BufferEnd-BufferStart; }
70
74
75
76
78
79
80
81
82
83
85
86
87
88
89
90
91
92
93
94
95
96
97
99 getFile(const Twine &Filename, bool IsText = false,
100 bool RequiresNullTerminator = true, bool IsVolatile = false,
101 std::optional Alignment = std::nullopt);
102
103
104
105
107 getFileAsStream(const Twine &Filename);
108
109
110
111
114 int64_t Offset, bool IsVolatile = false,
115 std::optional Alignment = std::nullopt);
116
117
118
119
120
121
122
123
124
125
128 bool RequiresNullTerminator = true, bool IsVolatile = false,
129 std::optional Alignment = std::nullopt);
130
131
132
133 static std::unique_ptr
135 bool RequiresNullTerminator = true);
136
137 static std::unique_ptr
138 getMemBuffer(MemoryBufferRef Ref, bool RequiresNullTerminator = true);
139
140
141
142 static std::unique_ptr
143 getMemBufferCopy(StringRef InputData, const Twine &BufferName = "");
144
145
147
148
149
151 getFileOrSTDIN(const Twine &Filename, bool IsText = false,
152 bool RequiresNullTerminator = true,
153 std::optional Alignment = std::nullopt);
154
155
158 bool IsVolatile = false,
159 std::optional Alignment = std::nullopt);
160
161
162
163
164
165
170
171
172
174
176};
177
178
179
180
181
183protected:
185
186public:
190
191
192
202
204 getFile(const Twine &Filename, bool IsVolatile = false,
205 std::optional Alignment = std::nullopt);
206
207
210 bool IsVolatile = false,
211 std::optional Alignment = std::nullopt);
212
213
214
215
216
217
218
219 LLVM_ABI static std::unique_ptr
221 std::optional Alignment = std::nullopt);
222
223
224
225
226 LLVM_ABI static std::unique_ptr
228
229private:
230
231
232
240};
241
242
243
244
245
247protected:
249
250public:
254
255
256
266
268 getFile(const Twine &Filename, int64_t FileSize = -1);
269
270
273
274private:
275
276
277
285};
286
287
289
290}
291
292#endif
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Provides ErrorOr smart pointer.
Represents either an error or a value T.
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< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition MemoryBuffer.h:166
@ MemoryBuffer_Malloc
Definition MemoryBuffer.h:167
@ MemoryBuffer_MMap
Definition MemoryBuffer.h:168
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition MemoryBuffer.h:77
size_t getBufferSize() const
Definition MemoryBuffer.h:69
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.
MemoryBuffer(const MemoryBuffer &)=delete
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.
virtual BufferKind getBufferKind() const =0
Return information on the memory mechanism used to support the MemoryBuffer.
void init(const char *BufStart, const char *BufEnd, bool RequiresNullTerminator)
init - Initialize this MemoryBuffer as a reference to externally allocated memory,...
StringRef getBuffer() const
Definition MemoryBuffer.h:71
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileAsStream(const Twine &Filename)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
virtual void dontNeedIfMmap()
For read-only MemoryBuffer_MMap, mark the buffer as unused in the near future and the kernel can free...
Definition MemoryBuffer.h:84
MemoryBufferRef getMemBufferRef() const
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 "-".
MemoryBuffer & operator=(const MemoryBuffer &)=delete
const char * getBufferEnd() const
Definition MemoryBuffer.h:68
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
const char * getBufferStart() const
Definition MemoryBuffer.h:67
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
MutableArrayRef< char > getBuffer()
Definition MemoryBuffer.h:199
static LLVM_ABI std::unique_ptr< WritableMemoryBuffer > getNewMemBuffer(size_t Size, const Twine &BufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
static LLVM_ABI ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFile(const Twine &Filename, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
WritableMemoryBuffer()=default
static LLVM_ABI std::unique_ptr< WritableMemoryBuffer > getNewUninitMemBuffer(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 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.
char * getBufferStart()
Definition MemoryBuffer.h:193
char * getBufferEnd()
Definition MemoryBuffer.h:196
WriteThroughMemoryBuffer()=default
MutableArrayRef< char > getBuffer()
Definition MemoryBuffer.h:263
char * getBufferEnd()
Definition MemoryBuffer.h:260
static LLVM_ABI ErrorOr< std::unique_ptr< WriteThroughMemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1)
char * getBufferStart()
Definition MemoryBuffer.h:257
static LLVM_ABI ErrorOr< std::unique_ptr< WriteThroughMemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset)
Map a subrange of the specified file as a ReadWriteMemoryBuffer.
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
This is an optimization pass for GlobalISel generic memory operations.
@ Ref
The access may reference the value stored in memory.