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

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_BINARYITEMSTREAM_H

10#define LLVM_SUPPORT_BINARYITEMSTREAM_H

11

16#include

17#include

18

19namespace llvm {

20

22 static size_t length(const T &Item) = delete;

24};

25

26

27

28

29

30

31

32

33template <typename T, typename Traits = BinaryItemTraits>

35public:

37

39

42 auto ExpectedIndex = translateOffsetIndex(Offset);

43 if (!ExpectedIndex)

44 return ExpectedIndex.takeError();

45 const auto &Item = Items[*ExpectedIndex];

47 return EC;

48 if (Size > Traits::length(Item))

52 }

53

56 auto ExpectedIndex = translateOffsetIndex(Offset);

57 if (!ExpectedIndex)

58 return ExpectedIndex.takeError();

59 Buffer = Traits::bytes(Items[*ExpectedIndex]);

61 }

62

64 Items = ItemArray;

65 computeItemOffsets();

66 }

67

69 return ItemEndOffsets.empty() ? 0 : ItemEndOffsets.back();

70 }

71

72private:

73 void computeItemOffsets() {

74 ItemEndOffsets.clear();

75 ItemEndOffsets.reserve(Items.size());

77 for (const auto &Item : Items) {

78 uint64_t Len = Traits::length(Item);

79 assert(Len > 0 && "no empty items");

80 CurrentOffset += Len;

81 ItemEndOffsets.push_back(CurrentOffset);

82 }

83 }

84

85 Expected<uint32_t> translateOffsetIndex(uint64_t Offset) {

86

91 size_t Idx = std::distance(ItemEndOffsets.begin(), Iter);

92 assert(Idx < Items.size() && "binary search for offset failed");

93 return Idx;

94 }

95

97 ArrayRef Items;

98

99

100 std::vector<uint64_t> ItemEndOffsets;

101};

102

103}

104

105#endif

Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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

ArrayRef< T > take_front(size_t N=1) const

Return a copy of *this with only the first N elements.

BinaryItemStream represents a sequence of objects stored in some kind of external container but for w...

llvm::endianness getEndian() const override

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.

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...

BinaryItemStream(llvm::endianness Endian)

uint64_t getLength() override

Return the number of bytes of data in this stream.

void setItems(ArrayRef< T > ItemArray)

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.

This is an optimization pass for GlobalISel generic memory operations.

auto lower_bound(R &&Range, T &&Value)

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

static ArrayRef< uint8_t > bytes(const T &Item)=delete

static size_t length(const T &Item)=delete