LLVM: include/llvm/Support/BinaryByteStream.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10#ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H

11#define LLVM_SUPPORT_BINARYBYTESTREAM_H

12

20#include

21#include

22#include

23

24namespace llvm {

25

26

27

28

29

31public:

37

39

47

55

57

59

61 const char *CharData = reinterpret_cast<const char *>(Data.data());

63 }

64

65protected:

68};

69

70

71

72

73

83

84

85

86

87

89public:

93 : Data(Data), ImmutableStream(Data, Endian) {}

94

96 return ImmutableStream.getEndian();

97 }

98

101 return ImmutableStream.readBytes(Offset, Size, Buffer);

102 }

103

106 return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);

107 }

108

110

112 if (Buffer.empty())

114

116 return EC;

117

118 uint8_t *DataPtr = const_cast<uint8_t *>(Data.data());

119 ::memcpy(DataPtr + Offset, Buffer.data(), Buffer.size());

121 }

122

124

126

127private:

130};

131

132

133

135 std::vector<uint8_t> Data;

137

138public:

141

142 void clear() { Data.clear(); }

143

145

154

156 Data.insert(Data.begin() + Offset, Bytes.begin(), Bytes.end());

157 }

158

167

169

171 if (Buffer.empty())

173

174

175

176

177

178

179

182

184 if (RequiredSize > Data.size())

185 Data.resize(RequiredSize);

186

187 ::memcpy(Data.data() + Offset, Buffer.data(), Buffer.size());

189 }

190

192

193

195

197};

198

199

200

202private:

204 public:

205 StreamImpl(std::unique_ptr Buffer,

209 Buffer->getBufferEnd()),

210 Endian),

211 FileBuffer(std::move(Buffer)) {}

212

214 if (FileBuffer->commit())

218 }

219

220

222

223

225

226 private:

227 std::unique_ptr FileBuffer;

228 };

229

230public:

233 : Impl(std::move(Buffer), Endian) {}

234

236

239 return Impl.readBytes(Offset, Size, Buffer);

240 }

241

244 return Impl.readLongestContiguousChunk(Offset, Buffer);

245 }

246

248

252

254

255

257

258

260

261private:

262 StreamImpl Impl;

263};

264

265}

266

267#endif

BinaryStreamFlags getFlags() const override

Return the properties of this stream.

Definition BinaryByteStream.h:194

Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override

Attempt to write the given bytes into the stream at the desired offset.

Definition BinaryByteStream.h:170

void clear()

Definition BinaryByteStream.h:142

llvm::endianness getEndian() const override

Definition BinaryByteStream.h:144

AppendingBinaryByteStream(llvm::endianness Endian)

Definition BinaryByteStream.h:140

Error commit() override

For buffered streams, commits changes to the backing store.

Definition BinaryByteStream.h:191

MutableArrayRef< uint8_t > data()

Definition BinaryByteStream.h:196

uint64_t getLength() override

Return the number of bytes of data in this stream.

Definition BinaryByteStream.h:168

Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...

Definition BinaryByteStream.h:146

Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream, read as much as possible without copying any data.

Definition BinaryByteStream.h:159

void insert(uint64_t Offset, ArrayRef< uint8_t > Bytes)

Definition BinaryByteStream.h:155

AppendingBinaryByteStream()=default

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

bool empty() const

empty - Check if the array is empty.

ArrayRef< T > slice(size_t N, size_t M) const

slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.

An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.

Definition BinaryByteStream.h:30

ArrayRef< uint8_t > data() const

Definition BinaryByteStream.h:58

BinaryByteStream(ArrayRef< uint8_t > Data, llvm::endianness Endian)

Definition BinaryByteStream.h:33

ArrayRef< uint8_t > Data

Definition BinaryByteStream.h:67

Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream, read as much as possible without copying any data.

Definition BinaryByteStream.h:48

BinaryByteStream()=default

Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...

Definition BinaryByteStream.h:40

llvm::endianness Endian

Definition BinaryByteStream.h:66

StringRef str() const

Definition BinaryByteStream.h:60

uint64_t getLength() override

Return the number of bytes of data in this stream.

Definition BinaryByteStream.h:56

llvm::endianness getEndian() const override

Definition BinaryByteStream.h:38

BinaryByteStream(StringRef Data, llvm::endianness Endian)

Definition BinaryByteStream.h:35

An interface for accessing data in a stream-like format, but which discourages copying.

Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize)

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

FileBufferByteStream(std::unique_ptr< FileOutputBuffer > Buffer, llvm::endianness Endian)

Definition BinaryByteStream.h:231

uint64_t getLength() override

Return the number of bytes of data in this stream.

Definition BinaryByteStream.h:247

llvm::endianness getEndian() const override

Definition BinaryByteStream.h:235

Error commit() override

For buffered streams, commits changes to the backing store.

Definition BinaryByteStream.h:253

Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream, read as much as possible without copying any data.

Definition BinaryByteStream.h:242

Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Data) override

Attempt to write the given bytes into the stream at the desired offset.

Definition BinaryByteStream.h:249

uint8_t * getBufferEnd() const

Returns a pointer to the end of the buffer.

Definition BinaryByteStream.h:259

uint8_t * getBufferStart() const

Returns a pointer to the start of the buffer.

Definition BinaryByteStream.h:256

Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...

Definition BinaryByteStream.h:237

std::unique_ptr< MemoryBuffer > MemBuffer

Definition BinaryByteStream.h:81

MemoryBufferByteStream(std::unique_ptr< MemoryBuffer > Buffer, llvm::endianness Endian)

Definition BinaryByteStream.h:76

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.

Definition BinaryByteStream.h:88

MutableArrayRef< uint8_t > data() const

Definition BinaryByteStream.h:125

uint64_t getLength() override

Return the number of bytes of data in this stream.

Definition BinaryByteStream.h:109

Error commit() override

For buffered streams, commits changes to the backing store.

Definition BinaryByteStream.h:123

llvm::endianness getEndian() const override

Definition BinaryByteStream.h:95

Error writeBytes(uint64_t Offset, ArrayRef< uint8_t > Buffer) override

Attempt to write the given bytes into the stream at the desired offset.

Definition BinaryByteStream.h:111

MutableBinaryByteStream(MutableArrayRef< uint8_t > Data, llvm::endianness Endian)

Definition BinaryByteStream.h:91

MutableBinaryByteStream()=default

Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream, read as much as possible without copying any data.

Definition BinaryByteStream.h:104

Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override

Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...

Definition BinaryByteStream.h:99

StringRef - Represent a constant reference to a string, i.e.

A BinaryStream which can be read from as well as written to.

Error checkOffsetForWrite(uint64_t Offset, uint64_t DataSize)

This is an optimization pass for GlobalISel generic memory operations.

Error make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

ArrayRef(const T &OneElt) -> ArrayRef< T >

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.