• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- FieldListRecordBuilder.cpp ----------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/CodeView/FieldListRecordBuilder.h"
11 
12 using namespace llvm;
13 using namespace codeview;
14 
FieldListRecordBuilder()15 FieldListRecordBuilder::FieldListRecordBuilder()
16     : ListRecordBuilder(TypeRecordKind::FieldList) {}
17 
writeBaseClass(const BaseClassRecord & Record)18 void FieldListRecordBuilder::writeBaseClass(const BaseClassRecord &Record) {
19   TypeRecordBuilder &Builder = getBuilder();
20 
21   Builder.writeTypeRecordKind(TypeRecordKind::BaseClass);
22   Builder.writeUInt16(static_cast<uint16_t>(Record.getAccess()));
23   Builder.writeTypeIndex(Record.getBaseType());
24   Builder.writeEncodedUnsignedInteger(Record.getBaseOffset());
25 
26   finishSubRecord();
27 }
28 
writeEnumerator(const EnumeratorRecord & Record)29 void FieldListRecordBuilder::writeEnumerator(const EnumeratorRecord &Record) {
30   TypeRecordBuilder &Builder = getBuilder();
31 
32   Builder.writeTypeRecordKind(TypeRecordKind::Enumerator);
33   Builder.writeUInt16(static_cast<uint16_t>(Record.getAccess()));
34   // FIXME: Handle full APInt such as __int128.
35   Builder.writeEncodedUnsignedInteger(Record.getValue().getZExtValue());
36   Builder.writeNullTerminatedString(Record.getName());
37 
38   finishSubRecord();
39 }
40 
writeDataMember(const DataMemberRecord & Record)41 void FieldListRecordBuilder::writeDataMember(const DataMemberRecord &Record) {
42   TypeRecordBuilder &Builder = getBuilder();
43 
44   Builder.writeTypeRecordKind(Record.getKind());
45   Builder.writeUInt16(static_cast<uint16_t>(Record.getAccess()));
46   Builder.writeTypeIndex(Record.getType());
47   Builder.writeEncodedUnsignedInteger(Record.getFieldOffset());
48   Builder.writeNullTerminatedString(Record.getName());
49 
50   finishSubRecord();
51 }
52 
writeOverloadedMethod(const OverloadedMethodRecord & Record)53 void FieldListRecordBuilder::writeOverloadedMethod(
54     const OverloadedMethodRecord &Record) {
55   TypeRecordBuilder &Builder = getBuilder();
56 
57   Builder.writeTypeRecordKind(TypeRecordKind::OverloadedMethod);
58   Builder.writeUInt16(Record.getNumOverloads());
59   Builder.writeTypeIndex(Record.getMethodList());
60   Builder.writeNullTerminatedString(Record.getName());
61 
62   finishSubRecord();
63 }
64 
writeOneMethod(const OneMethodRecord & Record)65 void FieldListRecordBuilder::writeOneMethod(const OneMethodRecord &Record) {
66   TypeRecordBuilder &Builder = getBuilder();
67 
68   uint16_t Flags = static_cast<uint16_t>(Record.getAccess());
69   Flags |= static_cast<uint16_t>(Record.getKind()) << MethodKindShift;
70   Flags |= static_cast<uint16_t>(Record.getOptions());
71 
72   Builder.writeTypeRecordKind(TypeRecordKind::OneMethod);
73   Builder.writeUInt16(Flags);
74   Builder.writeTypeIndex(Record.getType());
75   if (Record.isIntroducingVirtual()) {
76     assert(Record.getVFTableOffset() >= 0);
77     Builder.writeInt32(Record.getVFTableOffset());
78   } else {
79     assert(Record.getVFTableOffset() == -1);
80   }
81 
82   Builder.writeNullTerminatedString(Record.getName());
83 
84   finishSubRecord();
85 }
86 
writeNestedType(const NestedTypeRecord & Record)87 void FieldListRecordBuilder::writeNestedType(const NestedTypeRecord &Record) {
88   TypeRecordBuilder &Builder = getBuilder();
89 
90   Builder.writeTypeRecordKind(Record.getKind());
91   Builder.writeUInt16(0);
92   Builder.writeTypeIndex(Record.getNestedType());
93   Builder.writeNullTerminatedString(Record.getName());
94 
95   finishSubRecord();
96 }
97 
writeStaticDataMember(const StaticDataMemberRecord & Record)98 void FieldListRecordBuilder::writeStaticDataMember(
99     const StaticDataMemberRecord &Record) {
100   TypeRecordBuilder &Builder = getBuilder();
101 
102   Builder.writeTypeRecordKind(Record.getKind());
103   Builder.writeUInt16(static_cast<uint16_t>(Record.getAccess()));
104   Builder.writeTypeIndex(Record.getType());
105   Builder.writeNullTerminatedString(Record.getName());
106 
107   finishSubRecord();
108 }
109 
writeVirtualBaseClass(const VirtualBaseClassRecord & Record)110 void FieldListRecordBuilder::writeVirtualBaseClass(
111     const VirtualBaseClassRecord &Record) {
112   TypeRecordBuilder &Builder = getBuilder();
113 
114   Builder.writeTypeRecordKind(Record.getKind());
115   Builder.writeUInt16(static_cast<uint16_t>(Record.getAccess()));
116   Builder.writeTypeIndex(Record.getBaseType());
117   Builder.writeTypeIndex(Record.getVBPtrType());
118   Builder.writeEncodedInteger(Record.getVBPtrOffset());
119   Builder.writeEncodedUnsignedInteger(Record.getVTableIndex());
120 
121   finishSubRecord();
122 }
123 
writeVFPtr(const VFPtrRecord & Record)124 void FieldListRecordBuilder::writeVFPtr(const VFPtrRecord &Record) {
125   TypeRecordBuilder &Builder = getBuilder();
126 
127   Builder.writeTypeRecordKind(TypeRecordKind::VFPtr);
128   Builder.writeUInt16(0);
129   Builder.writeTypeIndex(Record.getType());
130 
131   finishSubRecord();
132 }
133