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

21#include

22#include <type_traits>

23#include

24

25namespace llvm {

26

27

28

29

30

31

33public:

39

41

43

45

46

47

48

49

50

51

53

54

55

56

57

58

59

61 static_assert(std::is_integral_v,

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

66 }

67

68

70 static_assert(std::is_enum::value,

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

72

74 }

75

76

77

78

79

80

82

83

84

85

86

87

89

90

91

92

93

94

95

96

98

99

100

101

102

103

104

106

107

108

109

110

111

112

114

115

116

117

118

119

120

122

123

124

125

126

127

128

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

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

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

133 "writeObject");

136 }

137

138

139

140

141

142

143

144

146 if (Array.empty())

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

151

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

155 }

156

157

158

159

160

161 template <typename T, typename U>

165

166

167

168

169

173

174

175 LLVM_ABI std::pair<BinaryStreamWriter, BinaryStreamWriter>

177

183

184protected:

187};

188

189}

190

191#endif

Lightweight arrays that are backed by an arbitrary BinaryStream.

This file contains library features backported from future STL versions.

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

BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.

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

Definition BinaryStreamWriter.h:170

Error writeArray(ArrayRef< T > Array)

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

Definition BinaryStreamWriter.h:145

uint64_t getOffset() const

Definition BinaryStreamWriter.h:179

uint64_t Offset

Definition BinaryStreamWriter.h:186

Error writeInteger(T Value)

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

Definition BinaryStreamWriter.h:60

LLVM_ABI Error writeSLEB128(int64_t Value)

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

uint64_t bytesRemaining() const

Definition BinaryStreamWriter.h:181

Error writeArray(VarStreamArray< T, U > Array)

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

Definition BinaryStreamWriter.h:162

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

BinaryStreamWriter()=default

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

Splits the Writer into two Writers at a given offset.

LLVM_ABI Error writeStreamRef(BinaryStreamRef Ref)

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

LLVM_ABI Error writeBytes(ArrayRef< uint8_t > Buffer)

Write the bytes specified in Buffer to the underlying stream.

uint64_t getLength() const

Definition BinaryStreamWriter.h:180

LLVM_ABI Error writeFixedString(StringRef Str)

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

void setOffset(uint64_t Off)

Definition BinaryStreamWriter.h:178

Error writeEnum(T Num)

Similar to writeInteger.

Definition BinaryStreamWriter.h:69

LLVM_ABI Error writeULEB128(uint64_t Value)

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

WritableBinaryStreamRef Stream

Definition BinaryStreamWriter.h:185

Error writeObject(const T &Obj)

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

Definition BinaryStreamWriter.h:129

BinaryStreamWriter(const BinaryStreamWriter &Other)=default

virtual ~BinaryStreamWriter()=default

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

void write(void *memory, value_type value, endianness endian)

Write a value to memory with a particular endianness.

This is an optimization pass for GlobalISel generic memory operations.

constexpr std::underlying_type_t< Enum > to_underlying(Enum E)

Returns underlying integer value of an enum.

Error make_error(ArgTs &&... Args)

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

@ Ref

The access may reference the value stored in memory.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

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