LLVM  8.0.1
SimpleTypeSerializer.cpp
Go to the documentation of this file.
2 
3 using namespace llvm;
4 using namespace llvm::codeview;
5 
8  Prefix.RecordKind = Kind;
9  Prefix.RecordLen = 0;
10  cantFail(Writer.writeObject(Prefix));
11 }
12 
13 static void addPadding(BinaryStreamWriter &Writer) {
14  uint32_t Align = Writer.getOffset() % 4;
15  if (Align == 0)
16  return;
17 
18  int PaddingBytes = 4 - Align;
19  while (PaddingBytes > 0) {
20  uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
21  cantFail(Writer.writeInteger(Pad));
22  --PaddingBytes;
23  }
24 }
25 
27 
29 
30 template <typename T>
32  BinaryStreamWriter Writer(ScratchBuffer, support::little);
33  TypeRecordMapping Mapping(Writer);
34 
35  CVType CVT;
36  CVT.Type = static_cast<TypeLeafKind>(Record.getKind());
37 
38  writeRecordPrefix(Writer, CVT.Type);
39 
40  cantFail(Mapping.visitTypeBegin(CVT));
41  cantFail(Mapping.visitKnownRecord(CVT, Record));
42  cantFail(Mapping.visitTypeEnd(CVT));
43 
44  addPadding(Writer);
45 
46  RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(ScratchBuffer.data());
47 
48  Prefix->RecordKind = CVT.kind();
49  Prefix->RecordLen = Writer.getOffset() - sizeof(uint16_t);
50 
51  return {ScratchBuffer.data(), Writer.getOffset()};
52 }
53 
54 // Explicitly instantiate the member function for each known type so that we can
55 // implement this in the cpp file.
56 #define TYPE_RECORD(EnumName, EnumVal, Name) \
57  template ArrayRef<uint8_t> llvm::codeview::SimpleTypeSerializer::serialize( \
58  Name##Record &Record);
59 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
60 #define MEMBER_RECORD(EnumName, EnumVal, Name)
61 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
62 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:704
static void addPadding(BinaryStreamWriter &Writer)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static void writeRecordPrefix(BinaryStreamWriter &Writer, TypeLeafKind Kind)
Kind kind() const
Definition: CVRecord.h:37
This class represents lattice values for constants.
Definition: AllocatorList.h:24
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
Error visitTypeEnd(CVType &Record) override
Error visitTypeBegin(CVType &Record) override
Paired begin/end actions for all types.
ArrayRef< uint8_t > serialize(T &Record)
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
const unsigned Kind