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

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_BINARYSTREAMWRITER_H

10#define LLVM_SUPPORT_BINARYSTREAMWRITER_H

11

19#include

20#include <type_traits>

21#include

22

23namespace llvm {

24

25

26

27

28

29

31public:

37

39

41

43

44

45

46

47

48

49

51

52

53

54

55

56

57

59 static_assert(std::is_integral_v,

60 "Cannot call writeInteger with non-integral value!");

64 }

65

66

68 static_assert(std::is_enum::value,

69 "Cannot call writeEnum with non-Enum type");

70

71 using U = std::underlying_type_t;

72 return writeInteger(static_cast<U>(Num));

73 }

74

75

76

77

78

79

81

82

83

84

85

86

88

89

90

91

92

93

94

95

97

98

99

100

101

102

103

105

106

107

108

109

110

111

113

114

115

116

117

118

119

121

122

123

124

125

126

127

129 static_assert(!std::is_pointer::value,

130 "writeObject should not be used with pointers, to write "

131 "the pointed-to value dereference the pointer before calling "

132 "writeObject");

135 }

136

137

138

139

140

141

142

143

145 if (Array.empty())

147 if (Array.size() > UINT32_MAX / sizeof(T))

148 return make_error(

150

153 Array.size() * sizeof(T)));

154 }

155

156

157

158

159

160 template <typename T, typename U>

163 }

164

165

166

167

168

171 }

172

173

174 std::pair<BinaryStreamWriter, BinaryStreamWriter> split(uint64_t Off) const;

175

181

182protected:

185};

186

187}

188

189#endif

Lightweight arrays that are backed by an arbitrary BinaryStream.

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

llvm::endianness getEndian() const

uint64_t getLength() const

BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.

Provides write only access to a subclass of WritableBinaryStream.

Error writeCString(StringRef Str)

Write the string Str to the underlying stream followed by a null terminator.

Error writeArray(FixedStreamArray< T > Array)

Writes all elements from the array Array to the underlying stream.

Error writeArray(ArrayRef< T > Array)

Writes an array of objects of type T to the underlying stream, as if by using memcpy.

uint64_t getOffset() const

Error writeInteger(T Value)

Write the integer Value to the underlying stream in the specified endianness.

Error writeSLEB128(int64_t Value)

Write the unsigned integer Value to the underlying stream using ULEB128 encoding.

uint64_t bytesRemaining() const

Error writeArray(VarStreamArray< T, U > Array)

Writes all data from the array Array to the underlying stream.

BinaryStreamWriter & operator=(const BinaryStreamWriter &Other)=default

BinaryStreamWriter()=default

std::pair< BinaryStreamWriter, BinaryStreamWriter > split(uint64_t Off) const

Splits the Writer into two Writers at a given offset.

Error writeStreamRef(BinaryStreamRef Ref)

Efficiently reads all data from Ref, and writes it to this stream.

Error writeBytes(ArrayRef< uint8_t > Buffer)

Write the bytes specified in Buffer to the underlying stream.

uint64_t getLength() const

Error writeFixedString(StringRef Str)

Write the string Str to the underlying stream without a null terminator.

void setOffset(uint64_t Off)

Error writeEnum(T Num)

Similar to writeInteger.

Error writeULEB128(uint64_t Value)

Write the unsigned integer Value to the underlying stream using ULEB128 encoding.

WritableBinaryStreamRef Stream

Error writeObject(const T &Obj)

Writes the object Obj to the underlying stream, as if by using memcpy.

BinaryStreamWriter(const BinaryStreamWriter &Other)=default

virtual ~BinaryStreamWriter()=default

Error padToAlignment(uint32_t Align)

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.

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.

LLVM Value Representation.

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

This is an optimization pass for GlobalISel generic memory operations.

@ Ref

The access may reference the value stored in memory.

This struct is a compact representation of a valid (non-zero power of two) alignment.