Line data Source code
1 : #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
2 :
3 : using namespace llvm;
4 : using namespace llvm::codeview;
5 :
6 3175 : static void writeRecordPrefix(BinaryStreamWriter &Writer, TypeLeafKind Kind) {
7 : RecordPrefix Prefix;
8 : Prefix.RecordKind = Kind;
9 : Prefix.RecordLen = 0;
10 3175 : cantFail(Writer.writeObject(Prefix));
11 3175 : }
12 :
13 3175 : static void addPadding(BinaryStreamWriter &Writer) {
14 3175 : uint32_t Align = Writer.getOffset() % 4;
15 3175 : if (Align == 0)
16 : return;
17 :
18 1213 : int PaddingBytes = 4 - Align;
19 3732 : while (PaddingBytes > 0) {
20 2519 : uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
21 2519 : cantFail(Writer.writeInteger(Pad));
22 2519 : --PaddingBytes;
23 : }
24 : }
25 :
26 6608 : SimpleTypeSerializer::SimpleTypeSerializer() : ScratchBuffer(MaxRecordLength) {}
27 :
28 6605 : SimpleTypeSerializer::~SimpleTypeSerializer() {}
29 :
30 : template <typename T>
31 3175 : ArrayRef<uint8_t> SimpleTypeSerializer::serialize(T &Record) {
32 3175 : BinaryStreamWriter Writer(ScratchBuffer, support::little);
33 : TypeRecordMapping Mapping(Writer);
34 :
35 : CVType CVT;
36 : CVT.Type = static_cast<TypeLeafKind>(Record.getKind());
37 :
38 3175 : writeRecordPrefix(Writer, CVT.Type);
39 :
40 3175 : cantFail(Mapping.visitTypeBegin(CVT));
41 3175 : cantFail(Mapping.visitKnownRecord(CVT, Record));
42 3175 : cantFail(Mapping.visitTypeEnd(CVT));
43 :
44 3175 : addPadding(Writer);
45 :
46 3175 : RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(ScratchBuffer.data());
47 :
48 3175 : Prefix->RecordKind = CVT.kind();
49 3175 : Prefix->RecordLen = Writer.getOffset() - sizeof(uint16_t);
50 :
51 3175 : 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"
|