]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/YamlTypeDumper.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303291, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / YamlTypeDumper.cpp
1 //===- YamlTypeDumper.cpp ------------------------------------- *- C++ --*-===//
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 "YamlTypeDumper.h"
11 #include "PdbYaml.h"
12 #include "YamlSerializationContext.h"
13
14 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
15 #include "llvm/DebugInfo/CodeView/EnumTables.h"
16 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
17 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
18 #include "llvm/DebugInfo/CodeView/TypeSerializer.h"
19 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
20 #include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
21
22 using namespace llvm;
23 using namespace llvm::codeview;
24 using namespace llvm::codeview::yaml;
25
26 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)
27 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint64_t)
28 LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord)
29 LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind)
30 LLVM_YAML_IS_SEQUENCE_VECTOR(StringRef)
31 LLVM_YAML_IS_SEQUENCE_VECTOR(CVType)
32 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbTpiFieldListRecord)
33
34 namespace {
35 struct FieldListRecordSplitter : public TypeVisitorCallbacks {
36 public:
37   explicit FieldListRecordSplitter(
38       std::vector<llvm::pdb::yaml::PdbTpiFieldListRecord> &Records)
39       : Records(Records) {}
40
41 #define TYPE_RECORD(EnumName, EnumVal, Name)
42 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
43 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
44 #define MEMBER_RECORD(EnumName, EnumVal, Name)                                 \
45   Error visitKnownMember(CVMemberRecord &CVT, Name##Record &Record) override { \
46     visitKnownMemberImpl(CVT);                                                 \
47     return Error::success();                                                   \
48   }
49 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
50
51 private:
52   void visitKnownMemberImpl(CVMemberRecord &CVT) {
53     llvm::pdb::yaml::PdbTpiFieldListRecord R;
54     R.Record = CVT;
55     Records.push_back(std::move(R));
56   }
57
58   std::vector<llvm::pdb::yaml::PdbTpiFieldListRecord> &Records;
59 };
60 }
61
62 namespace llvm {
63 namespace yaml {
64 template <> struct ScalarEnumerationTraits<PointerToMemberRepresentation> {
65   static void enumeration(IO &IO, PointerToMemberRepresentation &Value) {
66     IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown);
67     IO.enumCase(Value, "SingleInheritanceData",
68                 PointerToMemberRepresentation::SingleInheritanceData);
69     IO.enumCase(Value, "MultipleInheritanceData",
70                 PointerToMemberRepresentation::MultipleInheritanceData);
71     IO.enumCase(Value, "VirtualInheritanceData",
72                 PointerToMemberRepresentation::VirtualInheritanceData);
73     IO.enumCase(Value, "GeneralData",
74                 PointerToMemberRepresentation::GeneralData);
75     IO.enumCase(Value, "SingleInheritanceFunction",
76                 PointerToMemberRepresentation::SingleInheritanceFunction);
77     IO.enumCase(Value, "MultipleInheritanceFunction",
78                 PointerToMemberRepresentation::MultipleInheritanceFunction);
79     IO.enumCase(Value, "VirtualInheritanceFunction",
80                 PointerToMemberRepresentation::VirtualInheritanceFunction);
81     IO.enumCase(Value, "GeneralFunction",
82                 PointerToMemberRepresentation::GeneralFunction);
83   }
84 };
85
86 template <> struct ScalarEnumerationTraits<VFTableSlotKind> {
87   static void enumeration(IO &IO, VFTableSlotKind &Kind) {
88     IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16);
89     IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16);
90     IO.enumCase(Kind, "This", VFTableSlotKind::This);
91     IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer);
92     IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta);
93     IO.enumCase(Kind, "Near", VFTableSlotKind::Near);
94     IO.enumCase(Kind, "Far", VFTableSlotKind::Far);
95   }
96 };
97
98 template <> struct ScalarEnumerationTraits<CallingConvention> {
99   static void enumeration(IO &IO, CallingConvention &Value) {
100     IO.enumCase(Value, "NearC", CallingConvention::NearC);
101     IO.enumCase(Value, "FarC", CallingConvention::FarC);
102     IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal);
103     IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal);
104     IO.enumCase(Value, "NearFast", CallingConvention::NearFast);
105     IO.enumCase(Value, "FarFast", CallingConvention::FarFast);
106     IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall);
107     IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall);
108     IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall);
109     IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall);
110     IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall);
111     IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall);
112     IO.enumCase(Value, "Generic", CallingConvention::Generic);
113     IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall);
114     IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall);
115     IO.enumCase(Value, "SHCall", CallingConvention::SHCall);
116     IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall);
117     IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call);
118     IO.enumCase(Value, "TriCall", CallingConvention::TriCall);
119     IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call);
120     IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall);
121     IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall);
122     IO.enumCase(Value, "Inline", CallingConvention::Inline);
123     IO.enumCase(Value, "NearVector", CallingConvention::NearVector);
124   }
125 };
126
127 template <> struct ScalarEnumerationTraits<PointerKind> {
128   static void enumeration(IO &IO, PointerKind &Kind) {
129     IO.enumCase(Kind, "Near16", PointerKind::Near16);
130     IO.enumCase(Kind, "Far16", PointerKind::Far16);
131     IO.enumCase(Kind, "Huge16", PointerKind::Huge16);
132     IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment);
133     IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue);
134     IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue);
135     IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress);
136     IO.enumCase(Kind, "BasedOnSegmentAddress",
137                 PointerKind::BasedOnSegmentAddress);
138     IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType);
139     IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf);
140     IO.enumCase(Kind, "Near32", PointerKind::Near32);
141     IO.enumCase(Kind, "Far32", PointerKind::Far32);
142     IO.enumCase(Kind, "Near64", PointerKind::Near64);
143   }
144 };
145
146 template <> struct ScalarEnumerationTraits<PointerMode> {
147   static void enumeration(IO &IO, PointerMode &Mode) {
148     IO.enumCase(Mode, "Pointer", PointerMode::Pointer);
149     IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference);
150     IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember);
151     IO.enumCase(Mode, "PointerToMemberFunction",
152                 PointerMode::PointerToMemberFunction);
153     IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference);
154   }
155 };
156
157 template <> struct ScalarEnumerationTraits<HfaKind> {
158   static void enumeration(IO &IO, HfaKind &Value) {
159     IO.enumCase(Value, "None", HfaKind::None);
160     IO.enumCase(Value, "Float", HfaKind::Float);
161     IO.enumCase(Value, "Double", HfaKind::Double);
162     IO.enumCase(Value, "Other", HfaKind::Other);
163   }
164 };
165
166 template <> struct ScalarEnumerationTraits<MemberAccess> {
167   static void enumeration(IO &IO, MemberAccess &Access) {
168     IO.enumCase(Access, "None", MemberAccess::None);
169     IO.enumCase(Access, "Private", MemberAccess::Private);
170     IO.enumCase(Access, "Protected", MemberAccess::Protected);
171     IO.enumCase(Access, "Public", MemberAccess::Public);
172   }
173 };
174
175 template <> struct ScalarEnumerationTraits<MethodKind> {
176   static void enumeration(IO &IO, MethodKind &Kind) {
177     IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla);
178     IO.enumCase(Kind, "Virtual", MethodKind::Virtual);
179     IO.enumCase(Kind, "Static", MethodKind::Static);
180     IO.enumCase(Kind, "Friend", MethodKind::Friend);
181     IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual);
182     IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual);
183     IO.enumCase(Kind, "PureIntroducingVirtual",
184                 MethodKind::PureIntroducingVirtual);
185   }
186 };
187
188 template <> struct ScalarEnumerationTraits<WindowsRTClassKind> {
189   static void enumeration(IO &IO, WindowsRTClassKind &Value) {
190     IO.enumCase(Value, "None", WindowsRTClassKind::None);
191     IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass);
192     IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass);
193     IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface);
194   }
195 };
196
197 template <> struct ScalarEnumerationTraits<LabelType> {
198   static void enumeration(IO &IO, LabelType &Value) {
199     IO.enumCase(Value, "Near", LabelType::Near);
200     IO.enumCase(Value, "Far", LabelType::Far);
201   }
202 };
203
204 template <> struct ScalarBitSetTraits<PointerOptions> {
205   static void bitset(IO &IO, PointerOptions &Options) {
206     IO.bitSetCase(Options, "None", PointerOptions::None);
207     IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
208     IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
209     IO.bitSetCase(Options, "Const", PointerOptions::Const);
210     IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
211     IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
212     IO.bitSetCase(Options, "WinRTSmartPointer",
213                   PointerOptions::WinRTSmartPointer);
214   }
215 };
216
217 template <> struct ScalarBitSetTraits<ModifierOptions> {
218   static void bitset(IO &IO, ModifierOptions &Options) {
219     IO.bitSetCase(Options, "None", ModifierOptions::None);
220     IO.bitSetCase(Options, "Const", ModifierOptions::Const);
221     IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
222     IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
223   }
224 };
225
226 template <> struct ScalarBitSetTraits<FunctionOptions> {
227   static void bitset(IO &IO, FunctionOptions &Options) {
228     IO.bitSetCase(Options, "None", FunctionOptions::None);
229     IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
230     IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
231     IO.bitSetCase(Options, "ConstructorWithVirtualBases",
232                   FunctionOptions::ConstructorWithVirtualBases);
233   }
234 };
235
236 template <> struct ScalarBitSetTraits<ClassOptions> {
237   static void bitset(IO &IO, ClassOptions &Options) {
238     IO.bitSetCase(Options, "None", ClassOptions::None);
239     IO.bitSetCase(Options, "HasConstructorOrDestructor",
240                   ClassOptions::HasConstructorOrDestructor);
241     IO.bitSetCase(Options, "HasOverloadedOperator",
242                   ClassOptions::HasOverloadedOperator);
243     IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
244     IO.bitSetCase(Options, "ContainsNestedClass",
245                   ClassOptions::ContainsNestedClass);
246     IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
247                   ClassOptions::HasOverloadedAssignmentOperator);
248     IO.bitSetCase(Options, "HasConversionOperator",
249                   ClassOptions::HasConversionOperator);
250     IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
251     IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
252     IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
253     IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
254     IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
255   }
256 };
257
258 template <> struct ScalarBitSetTraits<MethodOptions> {
259   static void bitset(IO &IO, MethodOptions &Options) {
260     IO.bitSetCase(Options, "None", MethodOptions::None);
261     IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
262     IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
263     IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
264     IO.bitSetCase(Options, "CompilerGenerated",
265                   MethodOptions::CompilerGenerated);
266     IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
267   }
268 };
269
270 void ScalarTraits<APSInt>::output(const APSInt &S, void *,
271                                   llvm::raw_ostream &OS) {
272   S.print(OS, true);
273 }
274 StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
275   S = APSInt(Scalar);
276   return "";
277 }
278
279 bool ScalarTraits<APSInt>::mustQuote(StringRef Scalar) { return false; }
280
281 void MappingContextTraits<CVType, pdb::yaml::SerializationContext>::mapping(
282     IO &IO, CVType &Record, pdb::yaml::SerializationContext &Context) {
283   if (IO.outputting())
284     consumeError(codeview::visitTypeRecord(Record, Context.Dumper));
285 }
286
287 void MappingTraits<StringIdRecord>::mapping(IO &IO, StringIdRecord &String) {
288   IO.mapRequired("Id", String.Id);
289   IO.mapRequired("String", String.String);
290 }
291
292 void MappingTraits<ArgListRecord>::mapping(IO &IO, ArgListRecord &Args) {
293   IO.mapRequired("ArgIndices", Args.ArgIndices);
294 }
295
296 void MappingTraits<StringListRecord>::mapping(IO &IO, StringListRecord &Strings) {
297   IO.mapRequired("StringIndices", Strings.StringIndices);
298 }
299
300 void MappingTraits<ClassRecord>::mapping(IO &IO, ClassRecord &Class) {
301   IO.mapRequired("MemberCount", Class.MemberCount);
302   IO.mapRequired("Options", Class.Options);
303   IO.mapRequired("FieldList", Class.FieldList);
304   IO.mapRequired("Name", Class.Name);
305   IO.mapRequired("UniqueName", Class.UniqueName);
306   IO.mapRequired("DerivationList", Class.DerivationList);
307   IO.mapRequired("VTableShape", Class.VTableShape);
308   IO.mapRequired("Size", Class.Size);
309 }
310
311 void MappingTraits<UnionRecord>::mapping(IO &IO, UnionRecord &Union) {
312   IO.mapRequired("MemberCount", Union.MemberCount);
313   IO.mapRequired("Options", Union.Options);
314   IO.mapRequired("FieldList", Union.FieldList);
315   IO.mapRequired("Name", Union.Name);
316   IO.mapRequired("UniqueName", Union.UniqueName);
317   IO.mapRequired("Size", Union.Size);
318 }
319
320 void MappingTraits<EnumRecord>::mapping(IO &IO, EnumRecord &Enum) {
321   IO.mapRequired("NumEnumerators", Enum.MemberCount);
322   IO.mapRequired("Options", Enum.Options);
323   IO.mapRequired("FieldList", Enum.FieldList);
324   IO.mapRequired("Name", Enum.Name);
325   IO.mapRequired("UniqueName", Enum.UniqueName);
326   IO.mapRequired("UnderlyingType", Enum.UnderlyingType);
327 }
328
329 void MappingTraits<ArrayRecord>::mapping(IO &IO, ArrayRecord &AT) {
330   IO.mapRequired("ElementType", AT.ElementType);
331   IO.mapRequired("IndexType", AT.IndexType);
332   IO.mapRequired("Size", AT.Size);
333   IO.mapRequired("Name", AT.Name);
334 }
335
336 void MappingTraits<VFTableRecord>::mapping(IO &IO, VFTableRecord &VFT) {
337   IO.mapRequired("CompleteClass", VFT.CompleteClass);
338   IO.mapRequired("OverriddenVFTable", VFT.OverriddenVFTable);
339   IO.mapRequired("VFPtrOffset", VFT.VFPtrOffset);
340   IO.mapRequired("MethodNames", VFT.MethodNames);
341 }
342
343 void MappingTraits<MemberFuncIdRecord>::mapping(IO &IO,
344                                                 MemberFuncIdRecord &Id) {
345   IO.mapRequired("ClassType", Id.ClassType);
346   IO.mapRequired("FunctionType", Id.FunctionType);
347   IO.mapRequired("Name", Id.Name);
348 }
349
350 void MappingTraits<ProcedureRecord>::mapping(IO &IO, ProcedureRecord &Proc) {
351   IO.mapRequired("ReturnType", Proc.ReturnType);
352   IO.mapRequired("CallConv", Proc.CallConv);
353   IO.mapRequired("Options", Proc.Options);
354   IO.mapRequired("ParameterCount", Proc.ParameterCount);
355   IO.mapRequired("ArgumentList", Proc.ArgumentList);
356 }
357
358 void MappingTraits<MemberFunctionRecord>::mapping(IO &IO,
359                                                   MemberFunctionRecord &MF) {
360   IO.mapRequired("ReturnType", MF.ReturnType);
361   IO.mapRequired("ClassType", MF.ClassType);
362   IO.mapRequired("ThisType", MF.ThisType);
363   IO.mapRequired("CallConv", MF.CallConv);
364   IO.mapRequired("Options", MF.Options);
365   IO.mapRequired("ParameterCount", MF.ParameterCount);
366   IO.mapRequired("ArgumentList", MF.ArgumentList);
367   IO.mapRequired("ThisPointerAdjustment", MF.ThisPointerAdjustment);
368 }
369
370 void MappingTraits<MethodOverloadListRecord>::mapping(
371     IO &IO, MethodOverloadListRecord &MethodList) {
372   IO.mapRequired("Methods", MethodList.Methods);
373 }
374
375 void MappingTraits<FuncIdRecord>::mapping(IO &IO, FuncIdRecord &Func) {
376   IO.mapRequired("ParentScope", Func.ParentScope);
377   IO.mapRequired("FunctionType", Func.FunctionType);
378   IO.mapRequired("Name", Func.Name);
379 }
380
381 void MappingTraits<TypeServer2Record>::mapping(IO &IO, TypeServer2Record &TS) {
382   IO.mapRequired("Guid", TS.Guid);
383   IO.mapRequired("Age", TS.Age);
384   IO.mapRequired("Name", TS.Name);
385 }
386
387 void MappingTraits<PointerRecord>::mapping(IO &IO, PointerRecord &Ptr) {
388   IO.mapRequired("ReferentType", Ptr.ReferentType);
389   IO.mapRequired("Attrs", Ptr.Attrs);
390   IO.mapOptional("MemberInfo", Ptr.MemberInfo);
391 }
392
393 void MappingTraits<MemberPointerInfo>::mapping(IO &IO, MemberPointerInfo &MPI) {
394   IO.mapRequired("ContainingType", MPI.ContainingType);
395   IO.mapRequired("Representation", MPI.Representation);
396 }
397
398 void MappingTraits<ModifierRecord>::mapping(IO &IO, ModifierRecord &Mod) {
399   IO.mapRequired("ModifiedType", Mod.ModifiedType);
400   IO.mapRequired("Modifiers", Mod.Modifiers);
401 }
402
403 void MappingTraits<BitFieldRecord>::mapping(IO &IO, BitFieldRecord &BitField) {
404   IO.mapRequired("Type", BitField.Type);
405   IO.mapRequired("BitSize", BitField.BitSize);
406   IO.mapRequired("BitOffset", BitField.BitOffset);
407 }
408
409 void MappingTraits<VFTableShapeRecord>::mapping(IO &IO,
410                                                 VFTableShapeRecord &Shape) {
411   IO.mapRequired("Slots", Shape.Slots);
412 }
413
414 void MappingTraits<UdtSourceLineRecord>::mapping(IO &IO,
415                                                  UdtSourceLineRecord &Line) {
416   IO.mapRequired("UDT", Line.UDT);
417   IO.mapRequired("SourceFile", Line.SourceFile);
418   IO.mapRequired("LineNumber", Line.LineNumber);
419 }
420
421 void MappingTraits<UdtModSourceLineRecord>::mapping(
422     IO &IO, UdtModSourceLineRecord &Line) {
423   IO.mapRequired("UDT", Line.UDT);
424   IO.mapRequired("SourceFile", Line.SourceFile);
425   IO.mapRequired("LineNumber", Line.LineNumber);
426   IO.mapRequired("Module", Line.Module);
427 }
428
429 void MappingTraits<BuildInfoRecord>::mapping(IO &IO, BuildInfoRecord &Args) {
430   IO.mapRequired("ArgIndices", Args.ArgIndices);
431 }
432
433 void MappingTraits<LabelRecord>::mapping(IO &IO, LabelRecord &R) {
434   IO.mapRequired("Mode", R.Mode);
435 }
436
437 void MappingTraits<NestedTypeRecord>::mapping(IO &IO,
438                                               NestedTypeRecord &Nested) {
439   IO.mapRequired("Type", Nested.Type);
440   IO.mapRequired("Name", Nested.Name);
441 }
442
443 void MappingTraits<OneMethodRecord>::mapping(IO &IO, OneMethodRecord &Method) {
444   IO.mapRequired("Type", Method.Type);
445   IO.mapRequired("Attrs", Method.Attrs.Attrs);
446   IO.mapRequired("VFTableOffset", Method.VFTableOffset);
447   IO.mapRequired("Name", Method.Name);
448 }
449
450 void MappingTraits<OverloadedMethodRecord>::mapping(
451     IO &IO, OverloadedMethodRecord &Method) {
452   IO.mapRequired("NumOverloads", Method.NumOverloads);
453   IO.mapRequired("MethodList", Method.MethodList);
454   IO.mapRequired("Name", Method.Name);
455 }
456
457 void MappingTraits<DataMemberRecord>::mapping(IO &IO, DataMemberRecord &Field) {
458   IO.mapRequired("Attrs", Field.Attrs.Attrs);
459   IO.mapRequired("Type", Field.Type);
460   IO.mapRequired("FieldOffset", Field.FieldOffset);
461   IO.mapRequired("Name", Field.Name);
462 }
463
464 void MappingTraits<StaticDataMemberRecord>::mapping(
465     IO &IO, StaticDataMemberRecord &Field) {
466   IO.mapRequired("Attrs", Field.Attrs.Attrs);
467   IO.mapRequired("Type", Field.Type);
468   IO.mapRequired("Name", Field.Name);
469 }
470
471 void MappingTraits<VFPtrRecord>::mapping(IO &IO, VFPtrRecord &VFTable) {
472   IO.mapRequired("Type", VFTable.Type);
473 }
474
475 void MappingTraits<EnumeratorRecord>::mapping(IO &IO, EnumeratorRecord &Enum) {
476   IO.mapRequired("Attrs", Enum.Attrs.Attrs);
477   IO.mapRequired("Value", Enum.Value);
478   IO.mapRequired("Name", Enum.Name);
479 }
480
481 void MappingTraits<BaseClassRecord>::mapping(IO &IO, BaseClassRecord &Base) {
482   IO.mapRequired("Attrs", Base.Attrs.Attrs);
483   IO.mapRequired("Type", Base.Type);
484   IO.mapRequired("Offset", Base.Offset);
485 }
486
487 void MappingTraits<VirtualBaseClassRecord>::mapping(
488     IO &IO, VirtualBaseClassRecord &Base) {
489   IO.mapRequired("Attrs", Base.Attrs.Attrs);
490   IO.mapRequired("BaseType", Base.BaseType);
491   IO.mapRequired("VBPtrType", Base.VBPtrType);
492   IO.mapRequired("VBPtrOffset", Base.VBPtrOffset);
493   IO.mapRequired("VTableIndex", Base.VTableIndex);
494 }
495
496 void MappingTraits<ListContinuationRecord>::mapping(
497     IO &IO, ListContinuationRecord &Cont) {
498   IO.mapRequired("ContinuationIndex", Cont.ContinuationIndex);
499 }
500
501 void ScalarTraits<codeview::TypeIndex>::output(const codeview::TypeIndex &S,
502                                                void *, llvm::raw_ostream &OS) {
503   OS << S.getIndex();
504 }
505 StringRef ScalarTraits<codeview::TypeIndex>::input(StringRef Scalar, void *Ctx,
506                                                    codeview::TypeIndex &S) {
507   uint32_t I;
508   StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
509   if (!Result.empty())
510     return Result;
511   S = TypeIndex(I);
512   return "";
513 }
514 bool ScalarTraits<codeview::TypeIndex>::mustQuote(StringRef Scalar) {
515   return false;
516 }
517
518 void ScalarEnumerationTraits<TypeLeafKind>::enumeration(IO &io,
519                                                         TypeLeafKind &Value) {
520   auto TypeLeafNames = getTypeLeafNames();
521   for (const auto &E : TypeLeafNames)
522     io.enumCase(Value, E.Name.str().c_str(), E.Value);
523 }
524 }
525 }
526
527 Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
528     CVType &CVR) {
529   YamlIO.mapRequired("Kind", CVR.Type);
530   return Error::success();
531 }
532
533 Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitMemberBegin(
534     CVMemberRecord &Record) {
535   YamlIO.mapRequired("Kind", Record.Kind);
536   return Error::success();
537 }
538
539 void llvm::codeview::yaml::YamlTypeDumperCallbacks::visitKnownRecordImpl(
540     const char *Name, CVType &CVR, FieldListRecord &FieldList) {
541   std::vector<llvm::pdb::yaml::PdbTpiFieldListRecord> FieldListRecords;
542   if (YamlIO.outputting()) {
543     // If we are outputting, then `FieldList.Data` contains a huge chunk of data
544     // representing the serialized list of members.  We need to split it up into
545     // individual CVType records where each record represents an individual
546     // member.  This way, we can simply map the entire thing as a Yaml sequence,
547     // which will recurse back to the standard handler for top-level fields
548     // (top-level and member fields all have the exact same Yaml syntax so use
549     // the same parser).
550     FieldListRecordSplitter Splitter(FieldListRecords);
551     consumeError(codeview::visitMemberRecordStream(FieldList.Data, Splitter));
552   }
553   // Note that if we're not outputting (i.e. Yaml -> PDB) the result of this
554   // mapping gets lost, as the records are simply stored in this locally scoped
555   // vector.  What's important though is they are all sharing a single
556   // Serializer
557   // instance (in `Context.ActiveSerializer`), and that is building up a list of
558   // all the types.  The fact that we need a throwaway vector here is just to
559   // appease the YAML API to treat this as a sequence and do this mapping once
560   // for each YAML Sequence element in the input Yaml stream.
561   YamlIO.mapRequired("FieldList", FieldListRecords, Context);
562 }
563
564 namespace llvm {
565 namespace yaml {
566 template <>
567 struct MappingContextTraits<pdb::yaml::PdbTpiFieldListRecord,
568                             pdb::yaml::SerializationContext> {
569   static void mapping(IO &IO, pdb::yaml::PdbTpiFieldListRecord &Obj,
570                       pdb::yaml::SerializationContext &Context) {
571     if (IO.outputting())
572       consumeError(codeview::visitMemberRecord(Obj.Record, Context.Dumper));
573     else {
574       // If we are not outputting, then the array contains no data starting out,
575       // and is instead populated from the sequence represented by the yaml --
576       // again, using the same logic that we use for top-level records.
577       assert(Context.ActiveSerializer && "There is no active serializer!");
578       codeview::TypeVisitorCallbackPipeline Pipeline;
579       pdb::TpiHashUpdater Hasher;
580
581       Pipeline.addCallbackToPipeline(Context.Dumper);
582       Pipeline.addCallbackToPipeline(*Context.ActiveSerializer);
583       Pipeline.addCallbackToPipeline(Hasher);
584       consumeError(
585           codeview::visitMemberRecord(Obj.Record, Pipeline, VDS_BytesExternal));
586     }
587   }
588 };
589 }
590 }