LLVM: lib/Support/BinaryStreamRef.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

11

12using namespace llvm;

13

14namespace {

15

17public:

18 ArrayRefImpl(ArrayRef<uint8_t> Data, endianness Endian) : BBS(Data, Endian) {}

19

20 llvm::endianness getEndian() const override { return BBS.getEndian(); }

22 ArrayRef<uint8_t> &Buffer) override {

23 return BBS.readBytes(Offset, Size, Buffer);

24 }

25 Error readLongestContiguousChunk(uint64_t Offset,

26 ArrayRef<uint8_t> &Buffer) override {

27 return BBS.readLongestContiguousChunk(Offset, Buffer);

28 }

29 uint64_t getLength() override { return BBS.getLength(); }

30

31private:

32 BinaryByteStream BBS;

33};

34

36public:

37 MutableArrayRefImpl(MutableArrayRef<uint8_t> Data, endianness Endian)

38 : BBS(Data, Endian) {}

39

40

41 llvm::endianness getEndian() const override { return BBS.getEndian(); }

43 ArrayRef<uint8_t> &Buffer) override {

44 return BBS.readBytes(Offset, Size, Buffer);

45 }

46 Error readLongestContiguousChunk(uint64_t Offset,

47 ArrayRef<uint8_t> &Buffer) override {

48 return BBS.readLongestContiguousChunk(Offset, Buffer);

49 }

50 uint64_t getLength() override { return BBS.getLength(); }

51

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

54 }

55 Error commit() override { return BBS.commit(); }

56

57private:

58 MutableBinaryByteStream BBS;

59};

60}

61

65 std::optional<uint64_t> Length)

72

79

83 return EC;

84

85 if (auto EC =

87 return EC;

88

89

90

92 if (Buffer.size() > MaxLength)

93 Buffer = Buffer.slice(0, MaxLength);

95}

96

99

102 std::optional<uint64_t> Length)

104

109

112 if (auto EC = checkOffsetForWrite(Offset, Data.size()))

113 return EC;

114

116}

117

121

122

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

size_t size() const

size - Get the array size.

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.

std::optional< uint64_t > Length

BinaryStreamRefBase()=default

BinaryStream * BorrowedImpl

Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize) const

uint64_t getLength() const

BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.

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

Given an Offset into this BinaryStreamRef, return a reference to the largest buffer the stream could ...

Definition BinaryStreamRef.cpp:80

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

Given an Offset into this StreamRef and a Size, return a reference to a buffer owned by the stream.

Definition BinaryStreamRef.cpp:73

BinaryStreamRef()=default

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

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

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.

WritableBinaryStreamRef()=default

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

Given an Offset into this WritableBinaryStreamRef and some input data, writes the data to the underly...

Definition BinaryStreamRef.cpp:110

LLVM_ABI Error commit()

For buffered streams, commits changes to the backing store.

Definition BinaryStreamRef.cpp:123

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

This is an optimization pass for GlobalISel generic memory operations.

auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)

Get the size of a range.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

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