]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/YamlTypeDumper.h
MFV 316870
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / YamlTypeDumper.h
1 //===- YamlTypeDumper.h --------------------------------------- *- 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 #ifndef LLVM_TOOLS_LLVMPDBDUMP_YAMLTYPEDUMPER_H
11 #define LLVM_TOOLS_LLVMPDBDUMP_YAMLTYPEDUMPER_H
12
13 #include "llvm/DebugInfo/CodeView/CodeView.h"
14 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
15 #include "llvm/Support/YAMLTraits.h"
16
17 namespace llvm {
18 namespace pdb {
19 namespace yaml {
20 struct SerializationContext;
21 }
22 }
23 namespace codeview {
24 namespace yaml {
25 class YamlTypeDumperCallbacks : public TypeVisitorCallbacks {
26 public:
27   YamlTypeDumperCallbacks(llvm::yaml::IO &IO,
28                           llvm::pdb::yaml::SerializationContext &Context)
29       : YamlIO(IO), Context(Context) {}
30
31   virtual Error visitTypeBegin(CVType &Record) override;
32   virtual Error visitMemberBegin(CVMemberRecord &Record) override;
33
34 #define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
35   Error visitKnownRecord(CVRecord<TypeLeafKind> &CVR, Name##Record &Record)    \
36       override {                                                               \
37     visitKnownRecordImpl(#Name, CVR, Record);                                  \
38     return Error::success();                                                   \
39   }
40 #define MEMBER_RECORD(EnumName, EnumVal, Name)                                 \
41   Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \
42     visitKnownMemberImpl(#Name, Record);                                       \
43     return Error::success();                                                   \
44   }
45 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
46 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
47 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
48
49 private:
50   template <typename T> void visitKnownMemberImpl(const char *Name, T &Record) {
51     YamlIO.mapRequired(Name, Record);
52   }
53
54   template <typename T>
55   void visitKnownRecordImpl(const char *Name, CVType &Type, T &Record) {
56     YamlIO.mapRequired(Name, Record);
57   }
58
59   void visitKnownRecordImpl(const char *Name, CVType &CVR,
60                             FieldListRecord &FieldList);
61
62   llvm::yaml::IO &YamlIO;
63   llvm::pdb::yaml::SerializationContext &Context;
64 };
65 }
66 }
67 namespace pdb {
68 namespace yaml {
69 struct SerializationContext;
70 }
71 }
72 }
73
74 namespace llvm {
75 namespace yaml {
76
77 template <> struct ScalarTraits<APSInt> {
78   static void output(const APSInt &S, void *, llvm::raw_ostream &OS);
79   static StringRef input(StringRef Scalar, void *Ctx, APSInt &S);
80   static bool mustQuote(StringRef Scalar);
81 };
82
83 template <> struct ScalarTraits<codeview::TypeIndex> {
84   static void output(const codeview::TypeIndex &S, void *,
85                      llvm::raw_ostream &OS);
86   static StringRef input(StringRef Scalar, void *Ctx, codeview::TypeIndex &S);
87   static bool mustQuote(StringRef Scalar);
88 };
89
90 template <> struct MappingTraits<codeview::MemberPointerInfo> {
91   static void mapping(IO &IO, codeview::MemberPointerInfo &Obj);
92 };
93
94 template <>
95 struct MappingContextTraits<codeview::CVType, pdb::yaml::SerializationContext> {
96   static void mapping(IO &IO, codeview::CVType &Obj,
97                       pdb::yaml::SerializationContext &Context);
98 };
99
100 template <> struct ScalarEnumerationTraits<codeview::TypeLeafKind> {
101   static void enumeration(IO &io, codeview::TypeLeafKind &Value);
102 };
103
104 #define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
105   template <> struct MappingTraits<codeview::Name##Record> {                   \
106     static void mapping(IO &IO, codeview::Name##Record &Obj);                  \
107   };
108 #define MEMBER_RECORD(EnumName, EnumVal, Name)                                 \
109   TYPE_RECORD(EnumName, EnumVal, Name)
110 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
111 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
112 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
113 }
114 }
115
116 #endif