LLVM: include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_DEBUGINFO_CODEVIEW_CODEVIEWRECORDIO_H

10#define LLVM_DEBUGINFO_CODEVIEW_CODEVIEWRECORDIO_H

11

19#include

20#include

21#include <type_traits>

22

23namespace llvm {

24

25template class ArrayRef;

27

31

43

45 uint32_t getCurrentOffset() const {

47 return Writer->getOffset();

49 return Reader->getOffset();

50 else

51 return 0;

52 }

53

54public:

55

57

58

60

61

63 : Streamer(&Streamer) {}

64

67

69

71 return (Streamer != nullptr) && (Reader == nullptr) && (Writer == nullptr);

72 }

74 return (Reader != nullptr) && (Streamer == nullptr) && (Writer == nullptr);

75 }

77 return (Writer != nullptr) && (Streamer == nullptr) && (Reader == nullptr);

78 }

79

81

86 Streamer->emitBytes(BytesSR);

87 incrStreamedLen(sizeof(T));

89 }

90

92 return Writer->writeObject(Value);

93

94 const T *ValuePtr;

95 if (auto EC = Reader->readObject(ValuePtr))

96 return EC;

97 Value = *ValuePtr;

99 }

100

103 emitComment(Comment);

104 Streamer->emitIntValue((int)Value, sizeof(T));

105 incrStreamedLen(sizeof(T));

107 }

108

110 return Writer->writeInteger(Value);

111

112 return Reader->readInteger(Value);

113 }

114

118

119 using U = std::underlying_type_t;

120 U X;

121

123 X = static_cast<U>(Value);

124

126 return EC;

127

129 Value = static_cast<T>(X);

130

132 }

133

139

141 const Twine &Comment = "");

142

143 template <typename SizeType, typename T, typename ElementMapper>

145 const Twine &Comment = "") {

146 SizeType Size;

148 Size = static_cast<SizeType>(Items.size());

149 emitComment(Comment);

150 Streamer->emitIntValue(Size, sizeof(Size));

151 incrStreamedLen(sizeof(Size));

152

153 for (auto &X : Items) {

154 if (auto EC = Mapper(*this, X))

155 return EC;

156 }

158 Size = static_cast<SizeType>(Items.size());

159 if (auto EC = Writer->writeInteger(Size))

160 return EC;

161

162 for (auto &X : Items) {

163 if (auto EC = Mapper(*this, X))

164 return EC;

165 }

166 } else {

167 if (auto EC = Reader->readInteger(Size))

168 return EC;

169 for (SizeType I = 0; I < Size; ++I) {

170 typename T::value_type Item;

171 if (auto EC = Mapper(*this, Item))

172 return EC;

173 Items.push_back(Item);

174 }

175 }

176

178 }

179

180 template <typename T, typename ElementMapper>

182 const Twine &Comment = "") {

183 emitComment(Comment);

185 for (auto &Item : Items) {

186 if (auto EC = Mapper(*this, Item))

187 return EC;

188 }

189 } else {

190 typename T::value_type Field;

191

192 while (!Reader->empty() && Reader->peek() < 0xf0 ) {

193 if (auto EC = Mapper(*this, Field))

194 return EC;

195 Items.push_back(Field);

196 }

197 }

199 }

200

202 const Twine &Comment = "");

204 const Twine &Comment = "");

205

208

211 return StreamedLen;

212 return 0;

213 }

214

216 if (isStreaming() && Streamer->isVerboseAsm())

217 Streamer->AddRawComment(T);

218 }

219

220private:

221 void emitEncodedSignedInteger(const int64_t &Value,

222 const Twine &Comment = "");

223 void emitEncodedUnsignedInteger(const uint64_t &Value,

224 const Twine &Comment = "");

225 Error writeEncodedSignedInteger(const int64_t &Value);

227

228 void incrStreamedLen(const uint64_t &Len) {

230 StreamedLen += Len;

231 }

232

233 void resetStreamedLen() {

235 StreamedLen = 4;

236 }

237

238 void emitComment(const Twine &Comment) {

240 Twine TComment(Comment);

241 if (!TComment.isTriviallyEmpty())

243 }

244 }

245

246 struct RecordLimit {

247 uint32_t BeginOffset;

248 std::optional<uint32_t> MaxLength;

249

250 std::optional<uint32_t> bytesRemaining(uint32_t CurrentOffset) const {

251 if (!MaxLength)

252 return std::nullopt;

253 assert(CurrentOffset >= BeginOffset);

254

255 uint32_t BytesUsed = CurrentOffset - BeginOffset;

256 if (BytesUsed >= *MaxLength)

257 return 0;

258 return *MaxLength - BytesUsed;

259 }

260 };

261

262 SmallVector<RecordLimit, 2> Limits;

263

264 BinaryStreamReader *Reader = nullptr;

265 BinaryStreamWriter *Writer = nullptr;

266 CodeViewRecordStreamer *Streamer = nullptr;

267 uint64_t StreamedLen = 0;

268};

269

270}

271}

272

273#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

OptimizedStructLayoutField Field

This file defines the SmallVector class.

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

An arbitrary precision integer that knows its signedness.

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

Provides read only access to a subclass of BinaryStream.

Provides write only access to a subclass of WritableBinaryStream.

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

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

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

LLVM Value Representation.

bool isStreaming() const

Definition CodeViewRecordIO.h:70

Error mapVectorTail(T &Items, const ElementMapper &Mapper, const Twine &Comment="")

Definition CodeViewRecordIO.h:181

CodeViewRecordIO(BinaryStreamWriter &Writer)

Definition CodeViewRecordIO.h:59

LLVM_ABI Error padToAlignment(uint32_t Align)

Error mapVectorN(T &Items, const ElementMapper &Mapper, const Twine &Comment="")

Definition CodeViewRecordIO.h:144

Error mapInteger(T &Value, const Twine &Comment="")

Definition CodeViewRecordIO.h:101

LLVM_ABI Error endRecord()

LLVM_ABI Error mapInteger(TypeIndex &TypeInd, const Twine &Comment="")

CodeViewRecordIO(BinaryStreamReader &Reader)

Definition CodeViewRecordIO.h:56

LLVM_ABI Error mapGuid(GUID &Guid, const Twine &Comment="")

LLVM_ABI Error mapStringZVectorZ(std::vector< StringRef > &Value, const Twine &Comment="")

bool isWriting() const

Definition CodeViewRecordIO.h:76

LLVM_ABI Error skipPadding()

LLVM_ABI Error mapStringZ(StringRef &Value, const Twine &Comment="")

Error mapObject(T &Value)

Definition CodeViewRecordIO.h:82

uint64_t getStreamedLen()

Definition CodeViewRecordIO.h:209

Error mapEnum(T &Value, const Twine &Comment="")

Definition CodeViewRecordIO.h:115

LLVM_ABI Error mapEncodedInteger(int64_t &Value, const Twine &Comment="")

LLVM_ABI Error beginRecord(std::optional< uint32_t > MaxLength)

LLVM_ABI Error mapByteVectorTail(ArrayRef< uint8_t > &Bytes, const Twine &Comment="")

CodeViewRecordIO(CodeViewRecordStreamer &Streamer)

Definition CodeViewRecordIO.h:62

LLVM_ABI uint32_t maxFieldLength() const

bool isReading() const

Definition CodeViewRecordIO.h:73

void emitRawComment(const Twine &T)

Definition CodeViewRecordIO.h:215

Definition CodeViewRecordIO.h:32

virtual void emitBytes(StringRef Data)=0

virtual bool isVerboseAsm()=0

virtual void AddComment(const Twine &T)=0

virtual void emitIntValue(uint64_t Value, unsigned Size)=0

virtual void emitBinaryData(StringRef Data)=0

virtual std::string getTypeName(TypeIndex TI)=0

virtual ~CodeViewRecordStreamer()=default

virtual void AddRawComment(const Twine &T)=0

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

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

This represents the 'GUID' type from windows.h.