Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 1 | //===- PdbYAML.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 "PdbYaml.h" |
Zachary Turner | 2f951ce | 2016-08-31 21:42:26 +0000 | [diff] [blame] | 11 | |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 12 | #include "YamlSerializationContext.h" |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 13 | #include "YamlSymbolDumper.h" |
| 14 | #include "YamlTypeDumper.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 15 | |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h" |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/SymbolSerializer.h" |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbackPipeline.h" |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/TypeDeserializer.h" |
Zachary Turner | 4efa0a4 | 2016-11-08 22:24:53 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/TypeSerializer.h" |
Zachary Turner | 2f951ce | 2016-08-31 21:42:26 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 25 | #include "llvm/DebugInfo/PDB/Native/TpiHashing.h" |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/PDB/PDBExtras.h" |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/PDB/PDBTypes.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace llvm; |
| 30 | using namespace llvm::pdb; |
| 31 | using namespace llvm::pdb::yaml; |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 32 | using namespace llvm::yaml; |
| 33 | |
| 34 | LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t) |
| 35 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef) |
| 36 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::NamedStreamMapping) |
| 37 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbDbiModuleInfo) |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 38 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbSymbolRecord) |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 39 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbTpiRecord) |
| 40 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 41 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 42 | namespace llvm { |
| 43 | namespace yaml { |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 44 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 45 | template <> struct ScalarTraits<llvm::pdb::PDB_UniqueId> { |
| 46 | static void output(const llvm::pdb::PDB_UniqueId &S, void *, |
| 47 | llvm::raw_ostream &OS) { |
| 48 | OS << S; |
| 49 | } |
| 50 | |
| 51 | static StringRef input(StringRef Scalar, void *Ctx, |
| 52 | llvm::pdb::PDB_UniqueId &S) { |
| 53 | if (Scalar.size() != 38) |
| 54 | return "GUID strings are 38 characters long"; |
| 55 | if (Scalar[0] != '{' || Scalar[37] != '}') |
| 56 | return "GUID is not enclosed in {}"; |
| 57 | if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' || |
| 58 | Scalar[24] != '-') |
| 59 | return "GUID sections are not properly delineated with dashes"; |
| 60 | |
Saleem Abdulrasool | de9f00e | 2016-12-30 19:42:13 +0000 | [diff] [blame] | 61 | uint8_t *OutBuffer = S.Guid; |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 62 | for (auto Iter = Scalar.begin(); Iter != Scalar.end();) { |
| 63 | if (*Iter == '-' || *Iter == '{' || *Iter == '}') { |
| 64 | ++Iter; |
| 65 | continue; |
| 66 | } |
| 67 | uint8_t Value = (llvm::hexDigitValue(*Iter) << 4); |
| 68 | ++Iter; |
| 69 | Value |= llvm::hexDigitValue(*Iter); |
| 70 | ++Iter; |
| 71 | *OutBuffer++ = Value; |
| 72 | } |
| 73 | |
| 74 | return ""; |
| 75 | } |
| 76 | |
| 77 | static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); } |
| 78 | }; |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 79 | |
| 80 | template <> struct ScalarEnumerationTraits<llvm::pdb::PDB_Machine> { |
| 81 | static void enumeration(IO &io, llvm::pdb::PDB_Machine &Value) { |
| 82 | io.enumCase(Value, "Invalid", PDB_Machine::Invalid); |
| 83 | io.enumCase(Value, "Am33", PDB_Machine::Am33); |
| 84 | io.enumCase(Value, "Amd64", PDB_Machine::Amd64); |
| 85 | io.enumCase(Value, "Arm", PDB_Machine::Arm); |
| 86 | io.enumCase(Value, "ArmNT", PDB_Machine::ArmNT); |
| 87 | io.enumCase(Value, "Ebc", PDB_Machine::Ebc); |
| 88 | io.enumCase(Value, "x86", PDB_Machine::x86); |
| 89 | io.enumCase(Value, "Ia64", PDB_Machine::Ia64); |
| 90 | io.enumCase(Value, "M32R", PDB_Machine::M32R); |
| 91 | io.enumCase(Value, "Mips16", PDB_Machine::Mips16); |
| 92 | io.enumCase(Value, "MipsFpu", PDB_Machine::MipsFpu); |
| 93 | io.enumCase(Value, "MipsFpu16", PDB_Machine::MipsFpu16); |
| 94 | io.enumCase(Value, "PowerPCFP", PDB_Machine::PowerPCFP); |
| 95 | io.enumCase(Value, "R4000", PDB_Machine::R4000); |
| 96 | io.enumCase(Value, "SH3", PDB_Machine::SH3); |
| 97 | io.enumCase(Value, "SH3DSP", PDB_Machine::SH3DSP); |
| 98 | io.enumCase(Value, "Thumb", PDB_Machine::Thumb); |
| 99 | io.enumCase(Value, "WceMipsV2", PDB_Machine::WceMipsV2); |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_DbiVer> { |
| 104 | static void enumeration(IO &io, llvm::pdb::PdbRaw_DbiVer &Value) { |
| 105 | io.enumCase(Value, "V41", llvm::pdb::PdbRaw_DbiVer::PdbDbiVC41); |
| 106 | io.enumCase(Value, "V50", llvm::pdb::PdbRaw_DbiVer::PdbDbiV50); |
| 107 | io.enumCase(Value, "V60", llvm::pdb::PdbRaw_DbiVer::PdbDbiV60); |
| 108 | io.enumCase(Value, "V70", llvm::pdb::PdbRaw_DbiVer::PdbDbiV70); |
| 109 | io.enumCase(Value, "V110", llvm::pdb::PdbRaw_DbiVer::PdbDbiV110); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_ImplVer> { |
| 114 | static void enumeration(IO &io, llvm::pdb::PdbRaw_ImplVer &Value) { |
| 115 | io.enumCase(Value, "VC2", llvm::pdb::PdbRaw_ImplVer::PdbImplVC2); |
| 116 | io.enumCase(Value, "VC4", llvm::pdb::PdbRaw_ImplVer::PdbImplVC4); |
| 117 | io.enumCase(Value, "VC41", llvm::pdb::PdbRaw_ImplVer::PdbImplVC41); |
| 118 | io.enumCase(Value, "VC50", llvm::pdb::PdbRaw_ImplVer::PdbImplVC50); |
| 119 | io.enumCase(Value, "VC98", llvm::pdb::PdbRaw_ImplVer::PdbImplVC98); |
| 120 | io.enumCase(Value, "VC70Dep", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70Dep); |
| 121 | io.enumCase(Value, "VC70", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70); |
| 122 | io.enumCase(Value, "VC80", llvm::pdb::PdbRaw_ImplVer::PdbImplVC80); |
| 123 | io.enumCase(Value, "VC110", llvm::pdb::PdbRaw_ImplVer::PdbImplVC110); |
| 124 | io.enumCase(Value, "VC140", llvm::pdb::PdbRaw_ImplVer::PdbImplVC140); |
| 125 | } |
| 126 | }; |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 127 | |
| 128 | template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_TpiVer> { |
| 129 | static void enumeration(IO &io, llvm::pdb::PdbRaw_TpiVer &Value) { |
| 130 | io.enumCase(Value, "VC40", llvm::pdb::PdbRaw_TpiVer::PdbTpiV40); |
| 131 | io.enumCase(Value, "VC41", llvm::pdb::PdbRaw_TpiVer::PdbTpiV41); |
| 132 | io.enumCase(Value, "VC50", llvm::pdb::PdbRaw_TpiVer::PdbTpiV50); |
| 133 | io.enumCase(Value, "VC70", llvm::pdb::PdbRaw_TpiVer::PdbTpiV70); |
| 134 | io.enumCase(Value, "VC80", llvm::pdb::PdbRaw_TpiVer::PdbTpiV80); |
| 135 | } |
| 136 | }; |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 140 | void MappingTraits<PdbObject>::mapping(IO &IO, PdbObject &Obj) { |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 141 | // Create a single serialization context that will be passed through the |
| 142 | // entire process of serializing / deserializing a Tpi Stream. This is |
| 143 | // especially important when we are going from Pdb -> Yaml because we need |
| 144 | // to maintain state in a TypeTableBuilder across mappings, and at the end of |
| 145 | // the entire process, we need to have one TypeTableBuilder that has every |
| 146 | // record. |
| 147 | pdb::yaml::SerializationContext Context(IO, Obj.Allocator); |
| 148 | |
| 149 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 150 | IO.mapOptional("MSF", Obj.Headers); |
| 151 | IO.mapOptional("StreamSizes", Obj.StreamSizes); |
| 152 | IO.mapOptional("StreamMap", Obj.StreamMap); |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 153 | IO.mapOptional("StringTable", Obj.StringTable); |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 154 | IO.mapOptional("PdbStream", Obj.PdbStream); |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 155 | IO.mapOptionalWithContext("DbiStream", Obj.DbiStream, Context); |
| 156 | IO.mapOptionalWithContext("TpiStream", Obj.TpiStream, Context); |
| 157 | IO.mapOptionalWithContext("IpiStream", Obj.IpiStream, Context); |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 160 | void MappingTraits<MSFHeaders>::mapping(IO &IO, MSFHeaders &Obj) { |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 161 | IO.mapOptional("SuperBlock", Obj.SuperBlock); |
| 162 | IO.mapOptional("NumDirectoryBlocks", Obj.NumDirectoryBlocks); |
| 163 | IO.mapOptional("DirectoryBlocks", Obj.DirectoryBlocks); |
| 164 | IO.mapOptional("NumStreams", Obj.NumStreams); |
| 165 | IO.mapOptional("FileSize", Obj.FileSize); |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 168 | void MappingTraits<msf::SuperBlock>::mapping(IO &IO, msf::SuperBlock &SB) { |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 169 | if (!IO.outputting()) { |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 170 | ::memcpy(SB.MagicBytes, msf::Magic, sizeof(msf::Magic)); |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 173 | using u32 = support::ulittle32_t; |
| 174 | IO.mapOptional("BlockSize", SB.BlockSize, u32(4096U)); |
| 175 | IO.mapOptional("FreeBlockMap", SB.FreeBlockMapBlock, u32(0U)); |
| 176 | IO.mapOptional("NumBlocks", SB.NumBlocks, u32(0U)); |
| 177 | IO.mapOptional("NumDirectoryBytes", SB.NumDirectoryBytes, u32(0U)); |
| 178 | IO.mapOptional("Unknown1", SB.Unknown1, u32(0U)); |
| 179 | IO.mapOptional("BlockMapAddr", SB.BlockMapAddr, u32(0U)); |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void MappingTraits<StreamBlockList>::mapping(IO &IO, StreamBlockList &SB) { |
| 183 | IO.mapRequired("Stream", SB.Blocks); |
| 184 | } |
| 185 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 186 | void MappingTraits<PdbInfoStream>::mapping(IO &IO, PdbInfoStream &Obj) { |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 187 | IO.mapOptional("Age", Obj.Age, 1U); |
| 188 | IO.mapOptional("Guid", Obj.Guid); |
| 189 | IO.mapOptional("Signature", Obj.Signature, 0U); |
| 190 | IO.mapOptional("Version", Obj.Version, PdbImplVC70); |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 193 | void MappingContextTraits<PdbDbiStream, pdb::yaml::SerializationContext>::mapping(IO &IO, PdbDbiStream &Obj, pdb::yaml::SerializationContext &Context) { |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 194 | IO.mapOptional("VerHeader", Obj.VerHeader, PdbDbiV70); |
| 195 | IO.mapOptional("Age", Obj.Age, 1U); |
| 196 | IO.mapOptional("BuildNumber", Obj.BuildNumber, uint16_t(0U)); |
| 197 | IO.mapOptional("PdbDllVersion", Obj.PdbDllVersion, 0U); |
| 198 | IO.mapOptional("PdbDllRbld", Obj.PdbDllRbld, uint16_t(0U)); |
| 199 | IO.mapOptional("Flags", Obj.Flags, uint16_t(1U)); |
| 200 | IO.mapOptional("MachineType", Obj.MachineType, PDB_Machine::x86); |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 201 | IO.mapOptionalWithContext("Modules", Obj.ModInfos, Context); |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 202 | } |
Zachary Turner | 5e534c7 | 2016-07-15 22:17:08 +0000 | [diff] [blame] | 203 | |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 204 | void MappingContextTraits<PdbTpiStream, pdb::yaml::SerializationContext>::mapping( |
| 205 | IO &IO, pdb::yaml::PdbTpiStream &Obj, pdb::yaml::SerializationContext &Context) { |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 206 | IO.mapOptional("Version", Obj.Version, PdbTpiV80); |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 207 | IO.mapRequired("Records", Obj.Records, Context); |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Zachary Turner | 5e534c7 | 2016-07-15 22:17:08 +0000 | [diff] [blame] | 210 | void MappingTraits<NamedStreamMapping>::mapping(IO &IO, |
| 211 | NamedStreamMapping &Obj) { |
| 212 | IO.mapRequired("Name", Obj.StreamName); |
| 213 | IO.mapRequired("StreamNum", Obj.StreamNumber); |
| 214 | } |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 215 | |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 216 | void MappingContextTraits<PdbSymbolRecord, pdb::yaml::SerializationContext>::mapping(IO &IO, PdbSymbolRecord &Obj, pdb::yaml::SerializationContext &Context) { |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 217 | codeview::SymbolVisitorCallbackPipeline Pipeline; |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 218 | codeview::SymbolSerializer Serializer(Context.Allocator); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 219 | codeview::SymbolDeserializer Deserializer(nullptr); |
| 220 | codeview::yaml::YamlSymbolDumper Dumper(IO); |
| 221 | |
| 222 | if (IO.outputting()) { |
| 223 | // For PDB to Yaml, deserialize into a high level record type, then dump it. |
| 224 | Pipeline.addCallbackToPipeline(Deserializer); |
| 225 | Pipeline.addCallbackToPipeline(Dumper); |
| 226 | } else { |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 227 | // For the other way around, dump it into a concrete structure, and then |
| 228 | // serialize it into the CVRecord. |
| 229 | Pipeline.addCallbackToPipeline(Dumper); |
| 230 | Pipeline.addCallbackToPipeline(Serializer); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | codeview::CVSymbolVisitor Visitor(Pipeline); |
| 234 | consumeError(Visitor.visitSymbolRecord(Obj.Record)); |
| 235 | } |
| 236 | |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 237 | void MappingContextTraits<PdbModiStream, pdb::yaml::SerializationContext>::mapping(IO &IO, PdbModiStream &Obj, pdb::yaml::SerializationContext &Context) { |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 238 | IO.mapOptional("Signature", Obj.Signature, 4U); |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 239 | IO.mapRequired("Records", Obj.Symbols, Context); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 242 | void MappingContextTraits<PdbDbiModuleInfo, pdb::yaml::SerializationContext>::mapping(IO &IO, PdbDbiModuleInfo &Obj, pdb::yaml::SerializationContext &Context) { |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 243 | IO.mapRequired("Module", Obj.Mod); |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame^] | 244 | IO.mapOptional("ObjFile", Obj.Obj, Obj.Mod); |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 245 | IO.mapOptional("SourceFiles", Obj.SourceFiles); |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 246 | IO.mapOptionalWithContext("Modi", Obj.Modi, Context); |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 247 | } |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 248 | |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 249 | void MappingContextTraits<PdbTpiRecord, pdb::yaml::SerializationContext>:: |
| 250 | mapping(IO &IO, pdb::yaml::PdbTpiRecord &Obj, |
| 251 | pdb::yaml::SerializationContext &Context) { |
| 252 | codeview::TypeVisitorCallbackPipeline Pipeline; |
| 253 | codeview::TypeDeserializer Deserializer; |
Zachary Turner | 4efa0a4 | 2016-11-08 22:24:53 +0000 | [diff] [blame] | 254 | codeview::TypeSerializer Serializer(Context.Allocator); |
Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 255 | pdb::TpiHashUpdater Hasher; |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 256 | |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 257 | if (IO.outputting()) { |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 258 | // For PDB to Yaml, deserialize into a high level record type, then dump it. |
Zachary Turner | 2f951ce | 2016-08-31 21:42:26 +0000 | [diff] [blame] | 259 | Pipeline.addCallbackToPipeline(Deserializer); |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 260 | Pipeline.addCallbackToPipeline(Context.Dumper); |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 261 | } else { |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 262 | // For Yaml to PDB, extract from the high level record type, then write it |
| 263 | // to bytes. |
Zachary Turner | 4efa0a4 | 2016-11-08 22:24:53 +0000 | [diff] [blame] | 264 | |
| 265 | // This might be interpreted as a hack, but serializing FieldList |
| 266 | // sub-records requires having access to the same serializer being used by |
| 267 | // the FieldList itself. |
| 268 | Context.ActiveSerializer = &Serializer; |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 269 | Pipeline.addCallbackToPipeline(Context.Dumper); |
| 270 | Pipeline.addCallbackToPipeline(Serializer); |
Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 271 | Pipeline.addCallbackToPipeline(Hasher); |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | codeview::CVTypeVisitor Visitor(Pipeline); |
| 275 | consumeError(Visitor.visitTypeRecord(Obj.Record)); |
Zachary Turner | 4efa0a4 | 2016-11-08 22:24:53 +0000 | [diff] [blame] | 276 | Context.ActiveSerializer = nullptr; |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 277 | } |