]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/YamlTypeDumper.cpp
MFV r317781:
[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/Raw/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 ScalarBitSetTraits<PointerOptions> {
198   static void bitset(IO &IO, PointerOptions &Options) {
199     IO.bitSetCase(Options, "None", PointerOptions::None);
200     IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
201     IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
202     IO.bitSetCase(Options, "Const", PointerOptions::Const);
203     IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
204     IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
205     IO.bitSetCase(Options, "WinRTSmartPointer",
206                   PointerOptions::WinRTSmartPointer);
207   }
208 };
209
210 template <> struct ScalarBitSetTraits<ModifierOptions> {
211   static void bitset(IO &IO, ModifierOptions &Options) {
212     IO.bitSetCase(Options, "None", ModifierOptions::None);
213     IO.bitSetCase(Options, "Const", ModifierOptions::Const);
214     IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
215     IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
216   }
217 };
218
219 template <> struct ScalarBitSetTraits<FunctionOptions> {
220   static void bitset(IO &IO, FunctionOptions &Options) {
221     IO.bitSetCase(Options, "None", FunctionOptions::None);
222     IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
223     IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
224     IO.bitSetCase(Options, "ConstructorWithVirtualBases",
225                   FunctionOptions::ConstructorWithVirtualBases);
226   }
227 };
228
229 template <> struct ScalarBitSetTraits<ClassOptions> {
230   static void bitset(IO &IO, ClassOptions &Options) {
231     IO.bitSetCase(Options, "None", ClassOptions::None);
232     IO.bitSetCase(Options, "HasConstructorOrDestructor",
233                   ClassOptions::HasConstructorOrDestructor);
234     IO.bitSetCase(Options, "HasOverloadedOperator",
235                   ClassOptions::HasOverloadedOperator);
236     IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
237     IO.bitSetCase(Options, "ContainsNestedClass",
238                   ClassOptions::ContainsNestedClass);
239     IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
240                   ClassOptions::HasOverloadedAssignmentOperator);
241     IO.bitSetCase(Options, "HasConversionOperator",
242                   ClassOptions::HasConversionOperator);
243     IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
244     IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
245     IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
246     IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
247     IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
248   }
249 };
250
251 template <> struct ScalarBitSetTraits<MethodOptions> {
252   static void bitset(IO &IO, MethodOptions &Options) {
253     IO.bitSetCase(Options, "None", MethodOptions::None);
254     IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
255     IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
256     IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
257     IO.bitSetCase(Options, "CompilerGenerated",
258                   MethodOptions::CompilerGenerated);
259     IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
260   }
261 };
262
263 void ScalarTraits<APSInt>::output(const APSInt &S, void *,
264                                   llvm::raw_ostream &OS) {
265   S.print(OS, true);
266 }
267 StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
268   S = APSInt(Scalar);
269   return "";
270 }
271
272 bool ScalarTraits<APSInt>::mustQuote(StringRef Scalar) { return false; }
273
274 void MappingContextTraits<CVType, pdb::yaml::SerializationContext>::mapping(
275     IO &IO, CVType &Record, pdb::yaml::SerializationContext &Context) {
276   if (IO.outputting()) {
277     codeview::TypeDeserializer Deserializer;
278
279     codeview::TypeVisitorCallbackPipeline Pipeline;
280     Pipeline.addCallbackToPipeline(Deserializer);
281     Pipeline.addCallbackToPipeline(Context.Dumper);
282
283     codeview::CVTypeVisitor Visitor(Pipeline);
284     consumeError(Visitor.visitTypeRecord(Record));
285   }
286 }
287
288 void MappingTraits<StringIdRecord>::mapping(IO &IO, StringIdRecord &String) {
289   IO.mapRequired("Id", String.Id);
290   IO.mapRequired("String", String.String);
291 }
292
293 void MappingTraits<ArgListRecord>::mapping(IO &IO, ArgListRecord &Args) {
294   IO.mapRequired("ArgIndices", Args.StringIndices);
295 }
296
297 void MappingTraits<ClassRecord>::mapping(IO &IO, ClassRecord &Class) {
298   IO.mapRequired("MemberCount", Class.MemberCount);
299   IO.mapRequired("Options", Class.Options);
300   IO.mapRequired("FieldList", Class.FieldList);
301   IO.mapRequired("Name", Class.Name);
302   IO.mapRequired("UniqueName", Class.UniqueName);
303   IO.mapRequired("DerivationList", Class.DerivationList);
304   IO.mapRequired("VTableShape", Class.VTableShape);
305   IO.mapRequired("Size", Class.Size);
306 }
307
308 void MappingTraits<UnionRecord>::mapping(IO &IO, UnionRecord &Union) {
309   IO.mapRequired("MemberCount", Union.MemberCount);
310   IO.mapRequired("Options", Union.Options);
311   IO.mapRequired("FieldList", Union.FieldList);
312   IO.mapRequired("Name", Union.Name);
313   IO.mapRequired("UniqueName", Union.UniqueName);
314   IO.mapRequired("Size", Union.Size);
315 }
316
317 void MappingTraits<EnumRecord>::mapping(IO &IO, EnumRecord &Enum) {
318   IO.mapRequired("NumEnumerators", Enum.MemberCount);
319   IO.mapRequired("Options", Enum.Options);
320   IO.mapRequired("FieldList", Enum.FieldList);
321   IO.mapRequired("Name", Enum.Name);
322   IO.mapRequired("UniqueName", Enum.UniqueName);
323   IO.mapRequired("UnderlyingType", Enum.UnderlyingType);
324 }
325
326 void MappingTraits<ArrayRecord>::mapping(IO &IO, ArrayRecord &AT) {
327   IO.mapRequired("ElementType", AT.ElementType);
328   IO.mapRequired("IndexType", AT.IndexType);
329   IO.mapRequired("Size", AT.Size);
330   IO.mapRequired("Name", AT.Name);
331 }
332
333 void MappingTraits<VFTableRecord>::mapping(IO &IO, VFTableRecord &VFT) {
334   IO.mapRequired("CompleteClass", VFT.CompleteClass);
335   IO.mapRequired("OverriddenVFTable", VFT.OverriddenVFTable);
336   IO.mapRequired("VFPtrOffset", VFT.VFPtrOffset);
337   IO.mapRequired("MethodNames", VFT.MethodNames);
338 }
339
340 void MappingTraits<MemberFuncIdRecord>::mapping(IO &IO,
341                                                 MemberFuncIdRecord &Id) {
342   IO.mapRequired("ClassType", Id.ClassType);
343   IO.mapRequired("FunctionType", Id.FunctionType);
344   IO.mapRequired("Name", Id.Name);
345 }
346
347 void MappingTraits<ProcedureRecord>::mapping(IO &IO, ProcedureRecord &Proc) {
348   IO.mapRequired("ReturnType", Proc.ReturnType);
349   IO.mapRequired("CallConv", Proc.CallConv);
350   IO.mapRequired("Options", Proc.Options);
351   IO.mapRequired("ParameterCount", Proc.ParameterCount);
352   IO.mapRequired("ArgumentList", Proc.ArgumentList);
353 }
354
355 void MappingTraits<MemberFunctionRecord>::mapping(IO &IO,
356                                                   MemberFunctionRecord &MF) {
357   IO.mapRequired("ReturnType", MF.ReturnType);
358   IO.mapRequired("ClassType", MF.ClassType);
359   IO.mapRequired("ThisType", MF.ThisType);
360   IO.mapRequired("CallConv", MF.CallConv);
361   IO.mapRequired("Options", MF.Options);
362   IO.mapRequired("ParameterCount", MF.ParameterCount);
363   IO.mapRequired("ArgumentList", MF.ArgumentList);
364   IO.mapRequired("ThisPointerAdjustment", MF.ThisPointerAdjustment);
365 }
366
367 void MappingTraits<MethodOverloadListRecord>::mapping(
368     IO &IO, MethodOverloadListRecord &MethodList) {
369   IO.mapRequired("Methods", MethodList.Methods);
370 }
371
372 void MappingTraits<FuncIdRecord>::mapping(IO &IO, FuncIdRecord &Func) {
373   IO.mapRequired("ParentScope", Func.ParentScope);
374   IO.mapRequired("FunctionType", Func.FunctionType);
375   IO.mapRequired("Name", Func.Name);
376 }
377
378 void MappingTraits<TypeServer2Record>::mapping(IO &IO, TypeServer2Record &TS) {
379   IO.mapRequired("Guid", TS.Guid);
380   IO.mapRequired("Age", TS.Age);
381   IO.mapRequired("Name", TS.Name);
382 }
383
384 void MappingTraits<PointerRecord>::mapping(IO &IO, PointerRecord &Ptr) {
385   IO.mapRequired("ReferentType", Ptr.ReferentType);
386   IO.mapRequired("Attrs", Ptr.Attrs);
387   IO.mapOptional("MemberInfo", Ptr.MemberInfo);
388 }
389
390 void MappingTraits<MemberPointerInfo>::mapping(IO &IO, MemberPointerInfo &MPI) {
391   IO.mapRequired("ContainingType", MPI.ContainingType);
392   IO.mapRequired("Representation", MPI.Representation);
393 }
394
395 void MappingTraits<ModifierRecord>::mapping(IO &IO, ModifierRecord &Mod) {
396   IO.mapRequired("ModifiedType", Mod.ModifiedType);
397   IO.mapRequired("Modifiers", Mod.Modifiers);
398 }
399
400 void MappingTraits<BitFieldRecord>::mapping(IO &IO, BitFieldRecord &BitField) {
401   IO.mapRequired("Type", BitField.Type);
402   IO.mapRequired("BitSize", BitField.BitSize);
403   IO.mapRequired("BitOffset", BitField.BitOffset);
404 }
405
406 void MappingTraits<VFTableShapeRecord>::mapping(IO &IO,
407                                                 VFTableShapeRecord &Shape) {
408   IO.mapRequired("Slots", Shape.Slots);
409 }
410
411 void MappingTraits<UdtSourceLineRecord>::mapping(IO &IO,
412                                                  UdtSourceLineRecord &Line) {
413   IO.mapRequired("UDT", Line.UDT);
414   IO.mapRequired("SourceFile", Line.SourceFile);
415   IO.mapRequired("LineNumber", Line.LineNumber);
416 }
417
418 void MappingTraits<UdtModSourceLineRecord>::mapping(
419     IO &IO, UdtModSourceLineRecord &Line) {
420   IO.mapRequired("UDT", Line.UDT);
421   IO.mapRequired("SourceFile", Line.SourceFile);
422   IO.mapRequired("LineNumber", Line.LineNumber);
423   IO.mapRequired("Module", Line.Module);
424 }
425
426 void MappingTraits<BuildInfoRecord>::mapping(IO &IO, BuildInfoRecord &Args) {
427   IO.mapRequired("ArgIndices", Args.ArgIndices);
428 }
429
430 void MappingTraits<NestedTypeRecord>::mapping(IO &IO,
431                                               NestedTypeRecord &Nested) {
432   IO.mapRequired("Type", Nested.Type);
433   IO.mapRequired("Name", Nested.Name);
434 }
435
436 void MappingTraits<OneMethodRecord>::mapping(IO &IO, OneMethodRecord &Method) {
437   IO.mapRequired("Type", Method.Type);
438   IO.mapRequired("Attrs", Method.Attrs.Attrs);
439   IO.mapRequired("VFTableOffset", Method.VFTableOffset);
440   IO.mapRequired("Name", Method.Name);
441 }
442
443 void MappingTraits<OverloadedMethodRecord>::mapping(
444     IO &IO, OverloadedMethodRecord &Method) {
445   IO.mapRequired("NumOverloads", Method.NumOverloads);
446   IO.mapRequired("MethodList", Method.MethodList);
447   IO.mapRequired("Name", Method.Name);
448 }
449
450 void MappingTraits<DataMemberRecord>::mapping(IO &IO, DataMemberRecord &Field) {
451   IO.mapRequired("Attrs", Field.Attrs.Attrs);
452   IO.mapRequired("Type", Field.Type);
453   IO.mapRequired("FieldOffset", Field.FieldOffset);
454   IO.mapRequired("Name", Field.Name);
455 }
456
457 void MappingTraits<StaticDataMemberRecord>::mapping(
458     IO &IO, StaticDataMemberRecord &Field) {
459   IO.mapRequired("Attrs", Field.Attrs.Attrs);
460   IO.mapRequired("Type", Field.Type);
461   IO.mapRequired("Name", Field.Name);
462 }
463
464 void MappingTraits<VFPtrRecord>::mapping(IO &IO, VFPtrRecord &VFTable) {
465   IO.mapRequired("Type", VFTable.Type);
466 }
467
468 void MappingTraits<EnumeratorRecord>::mapping(IO &IO, EnumeratorRecord &Enum) {
469   IO.mapRequired("Attrs", Enum.Attrs.Attrs);
470   IO.mapRequired("Value", Enum.Value);
471   IO.mapRequired("Name", Enum.Name);
472 }
473
474 void MappingTraits<BaseClassRecord>::mapping(IO &IO, BaseClassRecord &Base) {
475   IO.mapRequired("Attrs", Base.Attrs.Attrs);
476   IO.mapRequired("Type", Base.Type);
477   IO.mapRequired("Offset", Base.Offset);
478 }
479
480 void MappingTraits<VirtualBaseClassRecord>::mapping(
481     IO &IO, VirtualBaseClassRecord &Base) {
482   IO.mapRequired("Attrs", Base.Attrs.Attrs);
483   IO.mapRequired("BaseType", Base.BaseType);
484   IO.mapRequired("VBPtrType", Base.VBPtrType);
485   IO.mapRequired("VBPtrOffset", Base.VBPtrOffset);
486   IO.mapRequired("VTableIndex", Base.VTableIndex);
487 }
488
489 void MappingTraits<ListContinuationRecord>::mapping(
490     IO &IO, ListContinuationRecord &Cont) {
491   IO.mapRequired("ContinuationIndex", Cont.ContinuationIndex);
492 }
493
494 void ScalarTraits<codeview::TypeIndex>::output(const codeview::TypeIndex &S,
495                                                void *, llvm::raw_ostream &OS) {
496   OS << S.getIndex();
497 }
498 StringRef ScalarTraits<codeview::TypeIndex>::input(StringRef Scalar, void *Ctx,
499                                                    codeview::TypeIndex &S) {
500   uint32_t I;
501   StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
502   if (!Result.empty())
503     return Result;
504   S = TypeIndex(I);
505   return "";
506 }
507 bool ScalarTraits<codeview::TypeIndex>::mustQuote(StringRef Scalar) {
508   return false;
509 }
510
511 void ScalarEnumerationTraits<TypeLeafKind>::enumeration(IO &io,
512                                                         TypeLeafKind &Value) {
513   auto TypeLeafNames = getTypeLeafNames();
514   for (const auto &E : TypeLeafNames)
515     io.enumCase(Value, E.Name.str().c_str(), E.Value);
516 }
517 }
518 }
519
520 Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
521     CVType &CVR) {
522   YamlIO.mapRequired("Kind", CVR.Type);
523   return Error::success();
524 }
525
526 Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitMemberBegin(
527     CVMemberRecord &Record) {
528   YamlIO.mapRequired("Kind", Record.Kind);
529   return Error::success();
530 }
531
532 void llvm::codeview::yaml::YamlTypeDumperCallbacks::visitKnownRecordImpl(
533     const char *Name, CVType &CVR, FieldListRecord &FieldList) {
534   std::vector<llvm::pdb::yaml::PdbTpiFieldListRecord> FieldListRecords;
535   if (YamlIO.outputting()) {
536     // If we are outputting, then `FieldList.Data` contains a huge chunk of data
537     // representing the serialized list of members.  We need to split it up into
538     // individual CVType records where each record represents an individual
539     // member.  This way, we can simply map the entire thing as a Yaml sequence,
540     // which will recurse back to the standard handler for top-level fields
541     // (top-level and member fields all have the exact same Yaml syntax so use
542     // the same parser).
543     FieldListRecordSplitter Splitter(FieldListRecords);
544     CVTypeVisitor V(Splitter);
545     consumeError(V.visitFieldListMemberStream(FieldList.Data));
546     YamlIO.mapRequired("FieldList", FieldListRecords, Context);
547   } else {
548     // If we are not outputting, then the array contains no data starting out,
549     // and is instead populated from the sequence represented by the yaml --
550     // again, using the same logic that we use for top-level records.
551     assert(Context.ActiveSerializer && "There is no active serializer!");
552     codeview::TypeVisitorCallbackPipeline Pipeline;
553     pdb::TpiHashUpdater Hasher;
554
555     // For Yaml to PDB, dump it (to fill out the record fields from the Yaml)
556     // then serialize those fields to bytes, then update their hashes.
557     Pipeline.addCallbackToPipeline(Context.Dumper);
558     Pipeline.addCallbackToPipeline(*Context.ActiveSerializer);
559     Pipeline.addCallbackToPipeline(Hasher);
560
561     codeview::CVTypeVisitor Visitor(Pipeline);
562     YamlIO.mapRequired("FieldList", FieldListRecords, Visitor);
563   }
564 }
565
566 namespace llvm {
567 namespace yaml {
568 template <>
569 struct MappingContextTraits<pdb::yaml::PdbTpiFieldListRecord,
570                             pdb::yaml::SerializationContext> {
571   static void mapping(IO &IO, pdb::yaml::PdbTpiFieldListRecord &Obj,
572                       pdb::yaml::SerializationContext &Context) {
573     assert(IO.outputting());
574     codeview::TypeVisitorCallbackPipeline Pipeline;
575
576     msf::ByteStream Data(Obj.Record.Data);
577     msf::StreamReader FieldReader(Data);
578     codeview::FieldListDeserializer Deserializer(FieldReader);
579
580     // For PDB to Yaml, deserialize into a high level record type, then dump
581     // it.
582     Pipeline.addCallbackToPipeline(Deserializer);
583     Pipeline.addCallbackToPipeline(Context.Dumper);
584
585     codeview::CVTypeVisitor Visitor(Pipeline);
586     consumeError(Visitor.visitMemberRecord(Obj.Record));
587   }
588 };
589
590 template <>
591 struct MappingContextTraits<pdb::yaml::PdbTpiFieldListRecord,
592                             codeview::CVTypeVisitor> {
593   static void mapping(IO &IO, pdb::yaml::PdbTpiFieldListRecord &Obj,
594                       codeview::CVTypeVisitor &Visitor) {
595     consumeError(Visitor.visitMemberRecord(Obj.Record));
596   }
597 };
598 }
599 }