xref: /freebsd-src/contrib/llvm-project/llvm/lib/ObjectYAML/DWARFYAML.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines classes for handling the YAML representation of DWARF Debug
100b57cec5SDimitry Andric // Info.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "llvm/ObjectYAML/DWARFYAML.h"
155ffd83dbSDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
16e8d8bef9SDimitry Andric #include "llvm/Support/Errc.h"
17e8d8bef9SDimitry Andric #include "llvm/Support/Error.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric namespace llvm {
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric bool DWARFYAML::Data::isEmpty() const {
22e8d8bef9SDimitry Andric   return getNonEmptySectionNames().empty();
235ffd83dbSDimitry Andric }
245ffd83dbSDimitry Andric 
25e8d8bef9SDimitry Andric SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
265ffd83dbSDimitry Andric   SetVector<StringRef> SecNames;
27e8d8bef9SDimitry Andric   if (DebugStrings)
285ffd83dbSDimitry Andric     SecNames.insert("debug_str");
29e8d8bef9SDimitry Andric   if (DebugAranges)
305ffd83dbSDimitry Andric     SecNames.insert("debug_aranges");
31e8d8bef9SDimitry Andric   if (DebugRanges)
325ffd83dbSDimitry Andric     SecNames.insert("debug_ranges");
335ffd83dbSDimitry Andric   if (!DebugLines.empty())
345ffd83dbSDimitry Andric     SecNames.insert("debug_line");
35e8d8bef9SDimitry Andric   if (DebugAddr)
365ffd83dbSDimitry Andric     SecNames.insert("debug_addr");
37e8d8bef9SDimitry Andric   if (!DebugAbbrev.empty())
385ffd83dbSDimitry Andric     SecNames.insert("debug_abbrev");
395ffd83dbSDimitry Andric   if (!CompileUnits.empty())
405ffd83dbSDimitry Andric     SecNames.insert("debug_info");
415ffd83dbSDimitry Andric   if (PubNames)
425ffd83dbSDimitry Andric     SecNames.insert("debug_pubnames");
435ffd83dbSDimitry Andric   if (PubTypes)
445ffd83dbSDimitry Andric     SecNames.insert("debug_pubtypes");
455ffd83dbSDimitry Andric   if (GNUPubNames)
465ffd83dbSDimitry Andric     SecNames.insert("debug_gnu_pubnames");
475ffd83dbSDimitry Andric   if (GNUPubTypes)
485ffd83dbSDimitry Andric     SecNames.insert("debug_gnu_pubtypes");
49e8d8bef9SDimitry Andric   if (DebugStrOffsets)
50e8d8bef9SDimitry Andric     SecNames.insert("debug_str_offsets");
51e8d8bef9SDimitry Andric   if (DebugRnglists)
52e8d8bef9SDimitry Andric     SecNames.insert("debug_rnglists");
53e8d8bef9SDimitry Andric   if (DebugLoclists)
54e8d8bef9SDimitry Andric     SecNames.insert("debug_loclists");
55*0fca6ea1SDimitry Andric   if (DebugNames)
56*0fca6ea1SDimitry Andric     SecNames.insert("debug_names");
575ffd83dbSDimitry Andric   return SecNames;
580b57cec5SDimitry Andric }
590b57cec5SDimitry Andric 
60e8d8bef9SDimitry Andric Expected<DWARFYAML::Data::AbbrevTableInfo>
61e8d8bef9SDimitry Andric DWARFYAML::Data::getAbbrevTableInfoByID(uint64_t ID) const {
62e8d8bef9SDimitry Andric   if (AbbrevTableInfoMap.empty()) {
63e8d8bef9SDimitry Andric     uint64_t AbbrevTableOffset = 0;
6406c3fb27SDimitry Andric     for (const auto &[Index, AbbrevTable] : enumerate(DebugAbbrev)) {
65e8d8bef9SDimitry Andric       // If the abbrev table's ID isn't specified, we use the index as its ID.
6606c3fb27SDimitry Andric       uint64_t AbbrevTableID = AbbrevTable.ID.value_or(Index);
67e8d8bef9SDimitry Andric       auto It = AbbrevTableInfoMap.insert(
6806c3fb27SDimitry Andric           {AbbrevTableID, AbbrevTableInfo{/*Index=*/Index,
69e8d8bef9SDimitry Andric                                           /*Offset=*/AbbrevTableOffset}});
70e8d8bef9SDimitry Andric       if (!It.second)
71e8d8bef9SDimitry Andric         return createStringError(
72e8d8bef9SDimitry Andric             errc::invalid_argument,
73e8d8bef9SDimitry Andric             "the ID (%" PRIu64 ") of abbrev table with index %zu has been used "
74e8d8bef9SDimitry Andric             "by abbrev table with index %" PRIu64,
7506c3fb27SDimitry Andric             AbbrevTableID, Index, It.first->second.Index);
76e8d8bef9SDimitry Andric 
7706c3fb27SDimitry Andric       AbbrevTableOffset += getAbbrevTableContentByIndex(Index).size();
78e8d8bef9SDimitry Andric     }
79e8d8bef9SDimitry Andric   }
80e8d8bef9SDimitry Andric 
81e8d8bef9SDimitry Andric   auto It = AbbrevTableInfoMap.find(ID);
82e8d8bef9SDimitry Andric   if (It == AbbrevTableInfoMap.end())
83e8d8bef9SDimitry Andric     return createStringError(errc::invalid_argument,
84e8d8bef9SDimitry Andric                              "cannot find abbrev table whose ID is %" PRIu64,
85e8d8bef9SDimitry Andric                              ID);
86e8d8bef9SDimitry Andric   return It->second;
87e8d8bef9SDimitry Andric }
88e8d8bef9SDimitry Andric 
890b57cec5SDimitry Andric namespace yaml {
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
925ffd83dbSDimitry Andric   void *OldContext = IO.getContext();
935ffd83dbSDimitry Andric   DWARFYAML::DWARFContext DWARFCtx;
945ffd83dbSDimitry Andric   IO.setContext(&DWARFCtx);
950b57cec5SDimitry Andric   IO.mapOptional("debug_str", DWARF.DebugStrings);
96e8d8bef9SDimitry Andric   IO.mapOptional("debug_abbrev", DWARF.DebugAbbrev);
97e8d8bef9SDimitry Andric   IO.mapOptional("debug_aranges", DWARF.DebugAranges);
985ffd83dbSDimitry Andric   IO.mapOptional("debug_ranges", DWARF.DebugRanges);
990b57cec5SDimitry Andric   IO.mapOptional("debug_pubnames", DWARF.PubNames);
1000b57cec5SDimitry Andric   IO.mapOptional("debug_pubtypes", DWARF.PubTypes);
1015ffd83dbSDimitry Andric   DWARFCtx.IsGNUPubSec = true;
1020b57cec5SDimitry Andric   IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
1030b57cec5SDimitry Andric   IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
1040b57cec5SDimitry Andric   IO.mapOptional("debug_info", DWARF.CompileUnits);
1050b57cec5SDimitry Andric   IO.mapOptional("debug_line", DWARF.DebugLines);
1065ffd83dbSDimitry Andric   IO.mapOptional("debug_addr", DWARF.DebugAddr);
107e8d8bef9SDimitry Andric   IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets);
108e8d8bef9SDimitry Andric   IO.mapOptional("debug_rnglists", DWARF.DebugRnglists);
109e8d8bef9SDimitry Andric   IO.mapOptional("debug_loclists", DWARF.DebugLoclists);
110*0fca6ea1SDimitry Andric   IO.mapOptional("debug_names", DWARF.DebugNames);
1115ffd83dbSDimitry Andric   IO.setContext(OldContext);
1120b57cec5SDimitry Andric }
1130b57cec5SDimitry Andric 
114e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::AbbrevTable>::mapping(
115e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::AbbrevTable &AbbrevTable) {
116e8d8bef9SDimitry Andric   IO.mapOptional("ID", AbbrevTable.ID);
117e8d8bef9SDimitry Andric   IO.mapOptional("Table", AbbrevTable.Table);
118e8d8bef9SDimitry Andric }
119e8d8bef9SDimitry Andric 
1200b57cec5SDimitry Andric void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO,
1210b57cec5SDimitry Andric                                                DWARFYAML::Abbrev &Abbrev) {
1225ffd83dbSDimitry Andric   IO.mapOptional("Code", Abbrev.Code);
1230b57cec5SDimitry Andric   IO.mapRequired("Tag", Abbrev.Tag);
1240b57cec5SDimitry Andric   IO.mapRequired("Children", Abbrev.Children);
125e8d8bef9SDimitry Andric   IO.mapOptional("Attributes", Abbrev.Attributes);
1260b57cec5SDimitry Andric }
1270b57cec5SDimitry Andric 
128*0fca6ea1SDimitry Andric void MappingTraits<DWARFYAML::IdxForm>::mapping(IO &IO,
129*0fca6ea1SDimitry Andric                                                 DWARFYAML::IdxForm &IdxForm) {
130*0fca6ea1SDimitry Andric   IO.mapRequired("Idx", IdxForm.Idx);
131*0fca6ea1SDimitry Andric   IO.mapRequired("Form", IdxForm.Form);
132*0fca6ea1SDimitry Andric }
133*0fca6ea1SDimitry Andric 
134*0fca6ea1SDimitry Andric void MappingTraits<DWARFYAML::DebugNameAbbreviation>::mapping(
135*0fca6ea1SDimitry Andric     IO &IO, DWARFYAML::DebugNameAbbreviation &DebugNameAbbreviation) {
136*0fca6ea1SDimitry Andric   IO.mapRequired("Code", DebugNameAbbreviation.Code);
137*0fca6ea1SDimitry Andric   IO.mapRequired("Tag", DebugNameAbbreviation.Tag);
138*0fca6ea1SDimitry Andric   IO.mapRequired("Indices", DebugNameAbbreviation.Indices);
139*0fca6ea1SDimitry Andric }
140*0fca6ea1SDimitry Andric 
141*0fca6ea1SDimitry Andric void MappingTraits<DWARFYAML::DebugNameEntry>::mapping(
142*0fca6ea1SDimitry Andric     IO &IO, DWARFYAML::DebugNameEntry &DebugNameEntry) {
143*0fca6ea1SDimitry Andric   IO.mapRequired("Name", DebugNameEntry.NameStrp);
144*0fca6ea1SDimitry Andric   IO.mapRequired("Code", DebugNameEntry.Code);
145*0fca6ea1SDimitry Andric   IO.mapOptional("Values", DebugNameEntry.Values);
146*0fca6ea1SDimitry Andric }
147*0fca6ea1SDimitry Andric 
148*0fca6ea1SDimitry Andric void MappingTraits<DWARFYAML::DebugNamesSection>::mapping(
149*0fca6ea1SDimitry Andric     IO &IO, DWARFYAML::DebugNamesSection &DebugNames) {
150*0fca6ea1SDimitry Andric   IO.mapRequired("Abbreviations", DebugNames.Abbrevs);
151*0fca6ea1SDimitry Andric   IO.mapRequired("Entries", DebugNames.Entries);
152*0fca6ea1SDimitry Andric }
153*0fca6ea1SDimitry Andric 
1540b57cec5SDimitry Andric void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping(
1550b57cec5SDimitry Andric     IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) {
1560b57cec5SDimitry Andric   IO.mapRequired("Attribute", AttAbbrev.Attribute);
1570b57cec5SDimitry Andric   IO.mapRequired("Form", AttAbbrev.Form);
1580b57cec5SDimitry Andric   if(AttAbbrev.Form == dwarf::DW_FORM_implicit_const)
1590b57cec5SDimitry Andric     IO.mapRequired("Value", AttAbbrev.Value);
1600b57cec5SDimitry Andric }
1610b57cec5SDimitry Andric 
1620b57cec5SDimitry Andric void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping(
1630b57cec5SDimitry Andric     IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) {
1640b57cec5SDimitry Andric   IO.mapRequired("Address", Descriptor.Address);
1650b57cec5SDimitry Andric   IO.mapRequired("Length", Descriptor.Length);
1660b57cec5SDimitry Andric }
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO,
1695ffd83dbSDimitry Andric                                                DWARFYAML::ARange &ARange) {
1705ffd83dbSDimitry Andric   IO.mapOptional("Format", ARange.Format, dwarf::DWARF32);
171e8d8bef9SDimitry Andric   IO.mapOptional("Length", ARange.Length);
1725ffd83dbSDimitry Andric   IO.mapRequired("Version", ARange.Version);
1735ffd83dbSDimitry Andric   IO.mapRequired("CuOffset", ARange.CuOffset);
174e8d8bef9SDimitry Andric   IO.mapOptional("AddressSize", ARange.AddrSize);
175e8d8bef9SDimitry Andric   IO.mapOptional("SegmentSelectorSize", ARange.SegSize, 0);
176e8d8bef9SDimitry Andric   IO.mapOptional("Descriptors", ARange.Descriptors);
1775ffd83dbSDimitry Andric }
1785ffd83dbSDimitry Andric 
1795ffd83dbSDimitry Andric void MappingTraits<DWARFYAML::RangeEntry>::mapping(
1805ffd83dbSDimitry Andric     IO &IO, DWARFYAML::RangeEntry &Descriptor) {
1815ffd83dbSDimitry Andric   IO.mapRequired("LowOffset", Descriptor.LowOffset);
1825ffd83dbSDimitry Andric   IO.mapRequired("HighOffset", Descriptor.HighOffset);
1835ffd83dbSDimitry Andric }
1845ffd83dbSDimitry Andric 
1855ffd83dbSDimitry Andric void MappingTraits<DWARFYAML::Ranges>::mapping(IO &IO,
1865ffd83dbSDimitry Andric                                                DWARFYAML::Ranges &DebugRanges) {
1875ffd83dbSDimitry Andric   IO.mapOptional("Offset", DebugRanges.Offset);
1885ffd83dbSDimitry Andric   IO.mapOptional("AddrSize", DebugRanges.AddrSize);
1895ffd83dbSDimitry Andric   IO.mapRequired("Entries", DebugRanges.Entries);
1900b57cec5SDimitry Andric }
1910b57cec5SDimitry Andric 
1920b57cec5SDimitry Andric void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO,
1930b57cec5SDimitry Andric                                                  DWARFYAML::PubEntry &Entry) {
1940b57cec5SDimitry Andric   IO.mapRequired("DieOffset", Entry.DieOffset);
1955ffd83dbSDimitry Andric   if (static_cast<DWARFYAML::DWARFContext *>(IO.getContext())->IsGNUPubSec)
1960b57cec5SDimitry Andric     IO.mapRequired("Descriptor", Entry.Descriptor);
1970b57cec5SDimitry Andric   IO.mapRequired("Name", Entry.Name);
1980b57cec5SDimitry Andric }
1990b57cec5SDimitry Andric 
2000b57cec5SDimitry Andric void MappingTraits<DWARFYAML::PubSection>::mapping(
2010b57cec5SDimitry Andric     IO &IO, DWARFYAML::PubSection &Section) {
202e8d8bef9SDimitry Andric   IO.mapOptional("Format", Section.Format, dwarf::DWARF32);
2030b57cec5SDimitry Andric   IO.mapRequired("Length", Section.Length);
2040b57cec5SDimitry Andric   IO.mapRequired("Version", Section.Version);
2050b57cec5SDimitry Andric   IO.mapRequired("UnitOffset", Section.UnitOffset);
2060b57cec5SDimitry Andric   IO.mapRequired("UnitSize", Section.UnitSize);
2070b57cec5SDimitry Andric   IO.mapRequired("Entries", Section.Entries);
2080b57cec5SDimitry Andric }
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
2115ffd83dbSDimitry Andric   IO.mapOptional("Format", Unit.Format, dwarf::DWARF32);
212e8d8bef9SDimitry Andric   IO.mapOptional("Length", Unit.Length);
2130b57cec5SDimitry Andric   IO.mapRequired("Version", Unit.Version);
2140b57cec5SDimitry Andric   if (Unit.Version >= 5)
2150b57cec5SDimitry Andric     IO.mapRequired("UnitType", Unit.Type);
216e8d8bef9SDimitry Andric   IO.mapOptional("AbbrevTableID", Unit.AbbrevTableID);
217e8d8bef9SDimitry Andric   IO.mapOptional("AbbrOffset", Unit.AbbrOffset);
218e8d8bef9SDimitry Andric   IO.mapOptional("AddrSize", Unit.AddrSize);
2190b57cec5SDimitry Andric   IO.mapOptional("Entries", Unit.Entries);
2200b57cec5SDimitry Andric }
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) {
2230b57cec5SDimitry Andric   IO.mapRequired("AbbrCode", Entry.AbbrCode);
224e8d8bef9SDimitry Andric   IO.mapOptional("Values", Entry.Values);
2250b57cec5SDimitry Andric }
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric void MappingTraits<DWARFYAML::FormValue>::mapping(
2280b57cec5SDimitry Andric     IO &IO, DWARFYAML::FormValue &FormValue) {
2290b57cec5SDimitry Andric   IO.mapOptional("Value", FormValue.Value);
2300b57cec5SDimitry Andric   if (!FormValue.CStr.empty() || !IO.outputting())
2310b57cec5SDimitry Andric     IO.mapOptional("CStr", FormValue.CStr);
2320b57cec5SDimitry Andric   if (!FormValue.BlockData.empty() || !IO.outputting())
2330b57cec5SDimitry Andric     IO.mapOptional("BlockData", FormValue.BlockData);
2340b57cec5SDimitry Andric }
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) {
2370b57cec5SDimitry Andric   IO.mapRequired("Name", File.Name);
2380b57cec5SDimitry Andric   IO.mapRequired("DirIdx", File.DirIdx);
2390b57cec5SDimitry Andric   IO.mapRequired("ModTime", File.ModTime);
2400b57cec5SDimitry Andric   IO.mapRequired("Length", File.Length);
2410b57cec5SDimitry Andric }
2420b57cec5SDimitry Andric 
2430b57cec5SDimitry Andric void MappingTraits<DWARFYAML::LineTableOpcode>::mapping(
2440b57cec5SDimitry Andric     IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) {
2450b57cec5SDimitry Andric   IO.mapRequired("Opcode", LineTableOpcode.Opcode);
2460b57cec5SDimitry Andric   if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) {
247e8d8bef9SDimitry Andric     IO.mapOptional("ExtLen", LineTableOpcode.ExtLen);
2480b57cec5SDimitry Andric     IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode);
2490b57cec5SDimitry Andric   }
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric   if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
2520b57cec5SDimitry Andric     IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData);
2530b57cec5SDimitry Andric   if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
2540b57cec5SDimitry Andric     IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData);
2550b57cec5SDimitry Andric   if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting())
2560b57cec5SDimitry Andric     IO.mapOptional("FileEntry", LineTableOpcode.FileEntry);
2570b57cec5SDimitry Andric   if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting())
2580b57cec5SDimitry Andric     IO.mapOptional("SData", LineTableOpcode.SData);
2590b57cec5SDimitry Andric   IO.mapOptional("Data", LineTableOpcode.Data);
2600b57cec5SDimitry Andric }
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric void MappingTraits<DWARFYAML::LineTable>::mapping(
2630b57cec5SDimitry Andric     IO &IO, DWARFYAML::LineTable &LineTable) {
2645ffd83dbSDimitry Andric   IO.mapOptional("Format", LineTable.Format, dwarf::DWARF32);
265e8d8bef9SDimitry Andric   IO.mapOptional("Length", LineTable.Length);
2660b57cec5SDimitry Andric   IO.mapRequired("Version", LineTable.Version);
267e8d8bef9SDimitry Andric   IO.mapOptional("PrologueLength", LineTable.PrologueLength);
2680b57cec5SDimitry Andric   IO.mapRequired("MinInstLength", LineTable.MinInstLength);
2690b57cec5SDimitry Andric   if(LineTable.Version >= 4)
2700b57cec5SDimitry Andric     IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst);
2710b57cec5SDimitry Andric   IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt);
2720b57cec5SDimitry Andric   IO.mapRequired("LineBase", LineTable.LineBase);
2730b57cec5SDimitry Andric   IO.mapRequired("LineRange", LineTable.LineRange);
274e8d8bef9SDimitry Andric   IO.mapOptional("OpcodeBase", LineTable.OpcodeBase);
275e8d8bef9SDimitry Andric   IO.mapOptional("StandardOpcodeLengths", LineTable.StandardOpcodeLengths);
276e8d8bef9SDimitry Andric   IO.mapOptional("IncludeDirs", LineTable.IncludeDirs);
277e8d8bef9SDimitry Andric   IO.mapOptional("Files", LineTable.Files);
278e8d8bef9SDimitry Andric   IO.mapOptional("Opcodes", LineTable.Opcodes);
2790b57cec5SDimitry Andric }
2800b57cec5SDimitry Andric 
2815ffd83dbSDimitry Andric void MappingTraits<DWARFYAML::SegAddrPair>::mapping(
2825ffd83dbSDimitry Andric     IO &IO, DWARFYAML::SegAddrPair &SegAddrPair) {
2835ffd83dbSDimitry Andric   IO.mapOptional("Segment", SegAddrPair.Segment, 0);
2845ffd83dbSDimitry Andric   IO.mapOptional("Address", SegAddrPair.Address, 0);
2855ffd83dbSDimitry Andric }
2865ffd83dbSDimitry Andric 
2875ffd83dbSDimitry Andric void MappingTraits<DWARFYAML::AddrTableEntry>::mapping(
2885ffd83dbSDimitry Andric     IO &IO, DWARFYAML::AddrTableEntry &AddrTable) {
2895ffd83dbSDimitry Andric   IO.mapOptional("Format", AddrTable.Format, dwarf::DWARF32);
2905ffd83dbSDimitry Andric   IO.mapOptional("Length", AddrTable.Length);
2915ffd83dbSDimitry Andric   IO.mapRequired("Version", AddrTable.Version);
2925ffd83dbSDimitry Andric   IO.mapOptional("AddressSize", AddrTable.AddrSize);
2935ffd83dbSDimitry Andric   IO.mapOptional("SegmentSelectorSize", AddrTable.SegSelectorSize, 0);
2945ffd83dbSDimitry Andric   IO.mapOptional("Entries", AddrTable.SegAddrPairs);
2955ffd83dbSDimitry Andric }
2965ffd83dbSDimitry Andric 
297e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::StringOffsetsTable>::mapping(
298e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable) {
299e8d8bef9SDimitry Andric   IO.mapOptional("Format", StrOffsetsTable.Format, dwarf::DWARF32);
300e8d8bef9SDimitry Andric   IO.mapOptional("Length", StrOffsetsTable.Length);
301e8d8bef9SDimitry Andric   IO.mapOptional("Version", StrOffsetsTable.Version, 5);
302e8d8bef9SDimitry Andric   IO.mapOptional("Padding", StrOffsetsTable.Padding, 0);
303e8d8bef9SDimitry Andric   IO.mapOptional("Offsets", StrOffsetsTable.Offsets);
304e8d8bef9SDimitry Andric }
305e8d8bef9SDimitry Andric 
306e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::DWARFOperation>::mapping(
307e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::DWARFOperation &DWARFOperation) {
308e8d8bef9SDimitry Andric   IO.mapRequired("Operator", DWARFOperation.Operator);
309e8d8bef9SDimitry Andric   IO.mapOptional("Values", DWARFOperation.Values);
310e8d8bef9SDimitry Andric }
311e8d8bef9SDimitry Andric 
312e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::RnglistEntry>::mapping(
313e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::RnglistEntry &RnglistEntry) {
314e8d8bef9SDimitry Andric   IO.mapRequired("Operator", RnglistEntry.Operator);
315e8d8bef9SDimitry Andric   IO.mapOptional("Values", RnglistEntry.Values);
316e8d8bef9SDimitry Andric }
317e8d8bef9SDimitry Andric 
318e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::LoclistEntry>::mapping(
319e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::LoclistEntry &LoclistEntry) {
320e8d8bef9SDimitry Andric   IO.mapRequired("Operator", LoclistEntry.Operator);
321e8d8bef9SDimitry Andric   IO.mapOptional("Values", LoclistEntry.Values);
322e8d8bef9SDimitry Andric   IO.mapOptional("DescriptionsLength", LoclistEntry.DescriptionsLength);
323e8d8bef9SDimitry Andric   IO.mapOptional("Descriptions", LoclistEntry.Descriptions);
324e8d8bef9SDimitry Andric }
325e8d8bef9SDimitry Andric 
326e8d8bef9SDimitry Andric template <typename EntryType>
327e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::ListEntries<EntryType>>::mapping(
328e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) {
329e8d8bef9SDimitry Andric   IO.mapOptional("Entries", ListEntries.Entries);
330e8d8bef9SDimitry Andric   IO.mapOptional("Content", ListEntries.Content);
331e8d8bef9SDimitry Andric }
332e8d8bef9SDimitry Andric 
333e8d8bef9SDimitry Andric template <typename EntryType>
334e8d8bef9SDimitry Andric std::string MappingTraits<DWARFYAML::ListEntries<EntryType>>::validate(
335e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) {
336e8d8bef9SDimitry Andric   if (ListEntries.Entries && ListEntries.Content)
337e8d8bef9SDimitry Andric     return "Entries and Content can't be used together";
338e8d8bef9SDimitry Andric   return "";
339e8d8bef9SDimitry Andric }
340e8d8bef9SDimitry Andric 
341e8d8bef9SDimitry Andric template <typename EntryType>
342e8d8bef9SDimitry Andric void MappingTraits<DWARFYAML::ListTable<EntryType>>::mapping(
343e8d8bef9SDimitry Andric     IO &IO, DWARFYAML::ListTable<EntryType> &ListTable) {
344e8d8bef9SDimitry Andric   IO.mapOptional("Format", ListTable.Format, dwarf::DWARF32);
345e8d8bef9SDimitry Andric   IO.mapOptional("Length", ListTable.Length);
346e8d8bef9SDimitry Andric   IO.mapOptional("Version", ListTable.Version, 5);
347e8d8bef9SDimitry Andric   IO.mapOptional("AddressSize", ListTable.AddrSize);
348e8d8bef9SDimitry Andric   IO.mapOptional("SegmentSelectorSize", ListTable.SegSelectorSize, 0);
349e8d8bef9SDimitry Andric   IO.mapOptional("OffsetEntryCount", ListTable.OffsetEntryCount);
350e8d8bef9SDimitry Andric   IO.mapOptional("Offsets", ListTable.Offsets);
351e8d8bef9SDimitry Andric   IO.mapOptional("Lists", ListTable.Lists);
3520b57cec5SDimitry Andric }
3530b57cec5SDimitry Andric 
3540b57cec5SDimitry Andric } // end namespace yaml
3550b57cec5SDimitry Andric 
3560b57cec5SDimitry Andric } // end namespace llvm
357