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
24#include
25#include
26#include
27
28namespace llvm {
29namespace sys {
30namespace fs {
31
32#if defined(_WIN32)
33
35#else
37#endif
38}
39}
40
41
42
43
44
45
46
47
48
49
50
52 const char *BufferStart;
53 const char *BufferEnd;
54
55protected:
57
58 void init(const char *BufStart, const char *BufEnd,
59 bool RequiresNullTerminator);
60
61public:
65
67 const char *getBufferEnd() const { return BufferEnd; }
68 size_t getBufferSize() const { return BufferEnd-BufferStart; }
69
72 }
73
74
75
77
78
79
80
81
82
84
85
86
87
88
89
90
91
92
93
94
95
96
98 getFile(const Twine &Filename, bool IsText = false,
99 bool RequiresNullTerminator = true, bool IsVolatile = false,
100 std::optional Alignment = std::nullopt);
101
102
103
104
107
108
109
110
113 int64_t Offset, bool IsVolatile = false,
114 std::optional Alignment = std::nullopt);
115
116
117
118
119
120
121
122
123
124
127 bool RequiresNullTerminator = true, bool IsVolatile = false,
128 std::optional Alignment = std::nullopt);
129
130
131
132 static std::unique_ptr
134 bool RequiresNullTerminator = true);
135
136 static std::unique_ptr
138
139
140
141 static std::unique_ptr
143
144
146
147
148
151 bool RequiresNullTerminator = true,
152 std::optional Alignment = std::nullopt);
153
154
157 bool IsVolatile = false,
158 std::optional Alignment = std::nullopt);
159
160
161
162
163
164
169
170
171
173
175};
176
177
178
179
180
182protected:
184
185public:
189
190
191
194 }
197 }
200 }
201
203 getFile(const Twine &Filename, bool IsVolatile = false,
204 std::optional Alignment = std::nullopt);
205
206
209 bool IsVolatile = false,
210 std::optional Alignment = std::nullopt);
211
212
213
214
215
216
217
218 static std::unique_ptr
220 std::optional Alignment = std::nullopt);
221
222
223
224
225 static std::unique_ptr
227
228private:
229
230
231
239};
240
241
242
243
244
246protected:
248
249public:
253
254
255
258 }
261 }
264 }
265
267 getFile(const Twine &Filename, int64_t FileSize = -1);
268
269
272
273private:
274
275
276
284};
285
286
288
289}
290
291#endif
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Provides ErrorOr smart pointer.
Represents either an error or a value T.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
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.
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
size_t getBufferSize() const
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
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...
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
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.
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,...
const char * getBufferEnd() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
const char * getBufferStart() const
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...
This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying conte...
MutableArrayRef< char > getBuffer()
static std::unique_ptr< WritableMemoryBuffer > getNewMemBuffer(size_t Size, const Twine &BufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
static ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFile(const Twine &Filename, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
WritableMemoryBuffer()=default
static 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 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.
This class is an extension of MemoryBuffer, which allows write access to the underlying contents and ...
WriteThroughMemoryBuffer()=default
MutableArrayRef< char > getBuffer()
static ErrorOr< std::unique_ptr< WriteThroughMemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1)
static 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.