[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / include / llvm / ObjectYAML / DWARFYAML.h
blob525fd9a89242fe90345ef37afe3adeb1b39d6ce4
1 //===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file declares classes for handling the YAML representation
11 /// of DWARF Debug Info.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
16 #define LLVM_OBJECTYAML_DWARFYAML_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/Dwarf.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include <cstdint>
22 #include <vector>
24 namespace llvm {
25 namespace DWARFYAML {
27 struct InitialLength {
28 uint32_t TotalLength;
29 uint64_t TotalLength64;
31 bool isDWARF64() const { return TotalLength == UINT32_MAX; }
33 uint64_t getLength() const {
34 return isDWARF64() ? TotalLength64 : TotalLength;
37 void setLength(uint64_t Len) {
38 if (Len >= (uint64_t)UINT32_MAX) {
39 TotalLength64 = Len;
40 TotalLength = UINT32_MAX;
41 } else {
42 TotalLength = Len;
47 struct AttributeAbbrev {
48 llvm::dwarf::Attribute Attribute;
49 llvm::dwarf::Form Form;
50 llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values
53 struct Abbrev {
54 llvm::yaml::Hex32 Code;
55 llvm::dwarf::Tag Tag;
56 llvm::dwarf::Constants Children;
57 std::vector<AttributeAbbrev> Attributes;
60 struct ARangeDescriptor {
61 llvm::yaml::Hex64 Address;
62 uint64_t Length;
65 struct ARange {
66 InitialLength Length;
67 uint16_t Version;
68 uint32_t CuOffset;
69 uint8_t AddrSize;
70 uint8_t SegSize;
71 std::vector<ARangeDescriptor> Descriptors;
74 struct PubEntry {
75 llvm::yaml::Hex32 DieOffset;
76 llvm::yaml::Hex8 Descriptor;
77 StringRef Name;
80 struct PubSection {
81 InitialLength Length;
82 uint16_t Version;
83 uint32_t UnitOffset;
84 uint32_t UnitSize;
85 bool IsGNUStyle = false;
86 std::vector<PubEntry> Entries;
89 struct FormValue {
90 llvm::yaml::Hex64 Value;
91 StringRef CStr;
92 std::vector<llvm::yaml::Hex8> BlockData;
95 struct Entry {
96 llvm::yaml::Hex32 AbbrCode;
97 std::vector<FormValue> Values;
100 struct Unit {
101 InitialLength Length;
102 uint16_t Version;
103 llvm::dwarf::UnitType Type; // Added in DWARF 5
104 uint32_t AbbrOffset;
105 uint8_t AddrSize;
106 std::vector<Entry> Entries;
109 struct File {
110 StringRef Name;
111 uint64_t DirIdx;
112 uint64_t ModTime;
113 uint64_t Length;
116 struct LineTableOpcode {
117 dwarf::LineNumberOps Opcode;
118 uint64_t ExtLen;
119 dwarf::LineNumberExtendedOps SubOpcode;
120 uint64_t Data;
121 int64_t SData;
122 File FileEntry;
123 std::vector<llvm::yaml::Hex8> UnknownOpcodeData;
124 std::vector<llvm::yaml::Hex64> StandardOpcodeData;
127 struct LineTable {
128 InitialLength Length;
129 uint16_t Version;
130 uint64_t PrologueLength;
131 uint8_t MinInstLength;
132 uint8_t MaxOpsPerInst;
133 uint8_t DefaultIsStmt;
134 uint8_t LineBase;
135 uint8_t LineRange;
136 uint8_t OpcodeBase;
137 std::vector<uint8_t> StandardOpcodeLengths;
138 std::vector<StringRef> IncludeDirs;
139 std::vector<File> Files;
140 std::vector<LineTableOpcode> Opcodes;
143 struct Data {
144 bool IsLittleEndian;
145 std::vector<Abbrev> AbbrevDecls;
146 std::vector<StringRef> DebugStrings;
147 std::vector<ARange> ARanges;
148 PubSection PubNames;
149 PubSection PubTypes;
151 PubSection GNUPubNames;
152 PubSection GNUPubTypes;
154 std::vector<Unit> CompileUnits;
156 std::vector<LineTable> DebugLines;
158 bool isEmpty() const;
161 } // end namespace DWARFYAML
162 } // end namespace llvm
164 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
165 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
166 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
167 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
168 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
169 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
170 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry)
171 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
172 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
173 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
174 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File)
175 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable)
176 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode)
178 namespace llvm {
179 namespace yaml {
181 template <> struct MappingTraits<DWARFYAML::Data> {
182 static void mapping(IO &IO, DWARFYAML::Data &DWARF);
185 template <> struct MappingTraits<DWARFYAML::Abbrev> {
186 static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev);
189 template <> struct MappingTraits<DWARFYAML::AttributeAbbrev> {
190 static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev);
193 template <> struct MappingTraits<DWARFYAML::ARangeDescriptor> {
194 static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor);
197 template <> struct MappingTraits<DWARFYAML::ARange> {
198 static void mapping(IO &IO, DWARFYAML::ARange &Range);
201 template <> struct MappingTraits<DWARFYAML::PubEntry> {
202 static void mapping(IO &IO, DWARFYAML::PubEntry &Entry);
205 template <> struct MappingTraits<DWARFYAML::PubSection> {
206 static void mapping(IO &IO, DWARFYAML::PubSection &Section);
209 template <> struct MappingTraits<DWARFYAML::Unit> {
210 static void mapping(IO &IO, DWARFYAML::Unit &Unit);
213 template <> struct MappingTraits<DWARFYAML::Entry> {
214 static void mapping(IO &IO, DWARFYAML::Entry &Entry);
217 template <> struct MappingTraits<DWARFYAML::FormValue> {
218 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
221 template <> struct MappingTraits<DWARFYAML::File> {
222 static void mapping(IO &IO, DWARFYAML::File &File);
225 template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
226 static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
229 template <> struct MappingTraits<DWARFYAML::LineTable> {
230 static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
233 template <> struct MappingTraits<DWARFYAML::InitialLength> {
234 static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
237 #define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \
238 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
240 template <> struct ScalarEnumerationTraits<dwarf::Tag> {
241 static void enumeration(IO &io, dwarf::Tag &value) {
242 #include "llvm/BinaryFormat/Dwarf.def"
243 io.enumFallback<Hex16>(value);
247 #define HANDLE_DW_LNS(unused, name) \
248 io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name);
250 template <> struct ScalarEnumerationTraits<dwarf::LineNumberOps> {
251 static void enumeration(IO &io, dwarf::LineNumberOps &value) {
252 #include "llvm/BinaryFormat/Dwarf.def"
253 io.enumFallback<Hex8>(value);
257 #define HANDLE_DW_LNE(unused, name) \
258 io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name);
260 template <> struct ScalarEnumerationTraits<dwarf::LineNumberExtendedOps> {
261 static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) {
262 #include "llvm/BinaryFormat/Dwarf.def"
263 io.enumFallback<Hex16>(value);
267 #define HANDLE_DW_AT(unused, name, unused2, unused3) \
268 io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
270 template <> struct ScalarEnumerationTraits<dwarf::Attribute> {
271 static void enumeration(IO &io, dwarf::Attribute &value) {
272 #include "llvm/BinaryFormat/Dwarf.def"
273 io.enumFallback<Hex16>(value);
277 #define HANDLE_DW_FORM(unused, name, unused2, unused3) \
278 io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
280 template <> struct ScalarEnumerationTraits<dwarf::Form> {
281 static void enumeration(IO &io, dwarf::Form &value) {
282 #include "llvm/BinaryFormat/Dwarf.def"
283 io.enumFallback<Hex16>(value);
287 #define HANDLE_DW_UT(unused, name) \
288 io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
290 template <> struct ScalarEnumerationTraits<dwarf::UnitType> {
291 static void enumeration(IO &io, dwarf::UnitType &value) {
292 #include "llvm/BinaryFormat/Dwarf.def"
293 io.enumFallback<Hex8>(value);
297 template <> struct ScalarEnumerationTraits<dwarf::Constants> {
298 static void enumeration(IO &io, dwarf::Constants &value) {
299 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
300 io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
301 io.enumFallback<Hex16>(value);
305 } // end namespace yaml
306 } // end namespace llvm
308 #endif // LLVM_OBJECTYAML_DWARFYAML_H