llvm.org GIT mirror llvm / cd90344
[ObjectYAML] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306925 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 2 years ago
22 changed file(s) with 466 addition(s) and 277 deletion(s). Raw diff Collapse all Expand all
1414 #define LLVM_OBJECTYAML_COFFYAML_H
1515
1616 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/StringRef.h"
1718 #include "llvm/BinaryFormat/COFF.h"
1819 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
1920 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
2021 #include "llvm/ObjectYAML/YAML.h"
22 #include
23 #include
2124
2225 namespace llvm {
2326
2427 namespace COFF {
28
2529 inline Characteristics operator|(Characteristics a, Characteristics b) {
2630 uint32_t Ret = static_cast(a) | static_cast(b);
2731 return static_cast(Ret);
3842 uint16_t Ret = static_cast(a) | static_cast(b);
3943 return static_cast(Ret);
4044 }
41 }
45
46 } // end namespace COFF
4247
4348 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
4449 // to use yaml::IO, we use these structures which are closer to the source.
4550 namespace COFFYAML {
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
47 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
48 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
49
50 struct Relocation {
51 uint32_t VirtualAddress;
52 uint16_t Type;
53 StringRef SymbolName;
54 };
55
56 struct Section {
57 COFF::section Header;
58 unsigned Alignment = 0;
59 yaml::BinaryRef SectionData;
60 std::vector DebugS;
61 std::vector DebugT;
62 std::vector Relocations;
63 StringRef Name;
64 Section();
65 };
66
67 struct Symbol {
68 COFF::symbol Header;
69 COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
70 COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
71 Optional FunctionDefinition;
72 Optional bfAndefSymbol;
73 Optional WeakExternal;
74 StringRef File;
75 Optional SectionDefinition;
76 Optional CLRToken;
77 StringRef Name;
78 Symbol();
79 };
80
81 struct PEHeader {
82 COFF::PE32Header Header;
83 Optional DataDirectories[COFF::NUM_DATA_DIRECTORIES];
84 };
85
86 struct Object {
87 Optional OptionalHeader;
88 COFF::header Header;
89 std::vector
Sections;
90 std::vector Symbols;
91 Object();
92 };
93 }
94 }
51
52 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
53 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
54 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
55
56 struct Relocation {
57 uint32_t VirtualAddress;
58 uint16_t Type;
59 StringRef SymbolName;
60 };
61
62 struct Section {
63 COFF::section Header;
64 unsigned Alignment = 0;
65 yaml::BinaryRef SectionData;
66 std::vector DebugS;
67 std::vector DebugT;
68 std::vector Relocations;
69 StringRef Name;
70
71 Section();
72 };
73
74 struct Symbol {
75 COFF::symbol Header;
76 COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
77 COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
78 Optional FunctionDefinition;
79 Optional bfAndefSymbol;
80 Optional WeakExternal;
81 StringRef File;
82 Optional SectionDefinition;
83 Optional CLRToken;
84 StringRef Name;
85
86 Symbol();
87 };
88
89 struct PEHeader {
90 COFF::PE32Header Header;
91 Optional DataDirectories[COFF::NUM_DATA_DIRECTORIES];
92 };
93
94 struct Object {
95 Optional OptionalHeader;
96 COFF::header Header;
97 std::vector
Sections;
98 std::vector Symbols;
99
100 Object();
101 };
102
103 } // end namespace COFFYAML
104
105 } // end namespace llvm
95106
96107 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
97108 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
223234 } // end namespace yaml
224235 } // end namespace llvm
225236
226 #endif
237 #endif // LLVM_OBJECTYAML_COFFYAML_H
None //===- CodeViewYAMLDebugSections.h - CodeView YAMLIO debug sections -------===//
0 //=- CodeViewYAMLDebugSections.h - CodeView YAMLIO debug sections -*- C++ -*-=//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1414 #ifndef LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H
1515 #define LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H
1616
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
1719 #include "llvm/DebugInfo/CodeView/CodeView.h"
1820 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
1921 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
20 #include "llvm/ObjectYAML/YAML.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/YAMLTraits.h"
24 #include
25 #include
26 #include
2127
2228 namespace llvm {
2329
2430 namespace codeview {
25 class DebugStringTableSubsection;
26 class DebugStringTableSubsectionRef;
27 class DebugChecksumsSubsectionRef;
28 class DebugStringTableSubsection;
29 class DebugChecksumsSubsection;
31
3032 class StringsAndChecksums;
3133 class StringsAndChecksumsRef;
32 }
34
35 } // end namespace codeview
36
3337 namespace CodeViewYAML {
3438
3539 namespace detail {
40
3641 struct YAMLSubsectionBase;
37 }
42
43 } // end namespace detail
3844
3945 struct YAMLFrameData {
4046 uint32_t RvaStart;
8692 uint32_t RelocSegment;
8793 codeview::LineFlags Flags;
8894 uint32_t CodeSize;
89
9095 std::vector Blocks;
9196 };
9297
123128 void initializeStringsAndChecksums(ArrayRef Sections,
124129 codeview::StringsAndChecksums &SC);
125130
126 } // namespace CodeViewYAML
127 } // namespace llvm
131 } // end namespace CodeViewYAML
132
133 } // end namespace llvm
128134
129135 LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::YAMLDebugSubsection)
130136
131137 LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::YAMLDebugSubsection)
132138
133 #endif
139 #endif // LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H
1616
1717 #include "llvm/DebugInfo/CodeView/CodeView.h"
1818 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
19 #include "llvm/ObjectYAML/YAML.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include
2022
2123 namespace llvm {
2224 namespace CodeViewYAML {
25
2326 namespace detail {
27
2428 struct SymbolRecordBase;
25 }
29
30 } // end namespace detail
2631
2732 struct SymbolRecord {
2833 std::shared_ptr Symbol;
3035 codeview::CVSymbol
3136 toCodeViewSymbol(BumpPtrAllocator &Allocator,
3237 codeview::CodeViewContainer Container) const;
38
3339 static Expected fromCodeViewSymbol(codeview::CVSymbol Symbol);
3440 };
3541
36 } // namespace CodeViewYAML
37 } // namespace llvm
42 } // end namespace CodeViewYAML
43 } // end namespace llvm
3844
3945 LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::SymbolRecord)
4046 LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::SymbolRecord)
4147
42 #endif
48 #endif // LLVM_OBJECTYAML_CODEVIEWYAMLSYMBOLS_H
None //===- CodeViewYAMLTypes.h - CodeView YAMLIO Type Record implementation ---===//
0 //==- CodeViewYAMLTypes.h - CodeView YAMLIO Type implementation --*- C++ -*-==//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1414 #ifndef LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H
1515 #define LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H
1616
17 #include "llvm/DebugInfo/CodeView/CodeView.h"
17 #include "llvm/ADT/ArrayRef.h"
1818 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
19 #include "llvm/ObjectYAML/YAML.h"
2019 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Error.h"
21 #include "llvm/Support/YAMLTraits.h"
22 #include
23 #include
24 #include
2125
2226 namespace llvm {
27
2328 namespace codeview {
29
2430 class TypeTableBuilder;
25 }
31
32 } // end namespace codeview
33
2634 namespace CodeViewYAML {
35
2736 namespace detail {
37
2838 struct LeafRecordBase;
2939 struct MemberRecordBase;
30 }
40
41 } // end namespace detail
3142
3243 struct MemberRecord {
3344 std::shared_ptr Member;
4354
4455 std::vector fromDebugT(ArrayRef DebugT);
4556 ArrayRef toDebugT(ArrayRef, BumpPtrAllocator &Alloc);
46 } // namespace CodeViewYAML
47 } // namespace llvm
57
58 } // end namespace CodeViewYAML
59
60 } // end namespace llvm
4861
4962 LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::LeafRecord)
5063 LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::MemberRecord)
5265 LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::LeafRecord)
5366 LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::MemberRecord)
5467
55 #endif
68 #endif // LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H
None //===--- DWARFEmitter.h - -------------------------------------------*- C++
1 //-*-===//
0 //===--- DWARFEmitter.h - ---------------------------------------*- C++ -*-===//
21 //
32 // The LLVM Compiler Infrastructure
43 //
98 /// \file
109 /// \brief Common declarations for yaml2obj
1110 //===----------------------------------------------------------------------===//
11
1212 #ifndef LLVM_OBJECTYAML_DWARFEMITTER_H
1313 #define LLVM_OBJECTYAML_DWARFEMITTER_H
1414
1818 #include "llvm/Support/Host.h"
1919 #include "llvm/Support/MemoryBuffer.h"
2020 #include
21 #include
2221
2322 namespace llvm {
23
2424 class raw_ostream;
2525
2626 namespace DWARFYAML {
27
2728 struct Data;
2829 struct PubSection;
2930
30 void EmitDebugAbbrev(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
31 void EmitDebugStr(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
31 void EmitDebugAbbrev(raw_ostream &OS, const Data &DI);
32 void EmitDebugStr(raw_ostream &OS, const Data &DI);
3233
33 void EmitDebugAranges(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
34 void EmitPubSection(llvm::raw_ostream &OS,
35 const llvm::DWARFYAML::PubSection &Sect,
34 void EmitDebugAranges(raw_ostream &OS, const Data &DI);
35 void EmitPubSection(raw_ostream &OS, const PubSection &Sect,
3636 bool IsLittleEndian);
37 void EmitDebugInfo(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
38 void EmitDebugLine(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
37 void EmitDebugInfo(raw_ostream &OS, const Data &DI);
38 void EmitDebugLine(raw_ostream &OS, const Data &DI);
3939
4040 Expected>>
4141 EmitDebugSections(StringRef YAMLString,
4242 bool IsLittleEndian = sys::IsLittleEndianHost);
4343
44 } // namespace DWARFYAML
45 } // namespace llvm
44 } // end namespace DWARFYAML
4645
47 #endif
46 } // end namespace llvm
47
48 #endif // LLVM_OBJECTYAML_DWARFEMITTER_H
1515 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
1616 #define LLVM_OBJECTYAML_DWARFYAML_H
1717
18 #include "llvm/ADT/StringRef.h"
1819 #include "llvm/BinaryFormat/Dwarf.h"
19 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include
22 #include
2023
2124 namespace llvm {
2225 namespace DWARFYAML {
7578 };
7679
7780 struct PubSection {
78 PubSection() : IsGNUStyle(false) {}
79
8081 InitialLength Length;
8182 uint16_t Version;
8283 uint32_t UnitOffset;
8384 uint32_t UnitSize;
84 bool IsGNUStyle;
85 bool IsGNUStyle = false;
8586 std::vector Entries;
8687 };
8788
157158 bool isEmpty() const;
158159 };
159160
160 } // namespace llvm::DWARFYAML
161 } // namespace llvm
161 } // end namespace DWARFYAML
162 } // end namespace llvm
162163
163164 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
164165 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
301302 }
302303 };
303304
304 } // namespace llvm::yaml
305 } // namespace llvm
306
307 #endif
305 } // end namespace yaml
306 } // end namespace llvm
307
308 #endif // LLVM_OBJECTYAML_DWARFYAML_H
1515 #ifndef LLVM_OBJECTYAML_ELFYAML_H
1616 #define LLVM_OBJECTYAML_ELFYAML_H
1717
18 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/ADT/StringRef.h"
1919 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include
22 #include
23 #include
2024
2125 namespace llvm {
2226 namespace ELFYAML {
6569 ELF_EF Flags;
6670 llvm::yaml::Hex64 Entry;
6771 };
72
6873 struct Symbol {
6974 StringRef Name;
7075 ELF_STT Type;
7378 llvm::yaml::Hex64 Size;
7479 uint8_t Other;
7580 };
81
7682 struct LocalGlobalWeakSymbols {
7783 std::vector Local;
7884 std::vector Global;
99105 StringRef Link;
100106 StringRef Info;
101107 llvm::yaml::Hex64 AddressAlign;
108
102109 Section(SectionKind Kind) : Kind(Kind) {}
103110 virtual ~Section();
104111 };
105112 struct RawContentSection : Section {
106113 yaml::BinaryRef Content;
107114 llvm::yaml::Hex64 Size;
115
108116 RawContentSection() : Section(SectionKind::RawContent) {}
117
109118 static bool classof(const Section *S) {
110119 return S->Kind == SectionKind::RawContent;
111120 }
113122
114123 struct NoBitsSection : Section {
115124 llvm::yaml::Hex64 Size;
125
116126 NoBitsSection() : Section(SectionKind::NoBits) {}
127
117128 static bool classof(const Section *S) {
118129 return S->Kind == SectionKind::NoBits;
119130 }
123134 // Members of a group contain a flag and a list of section indices
124135 // that are part of the group.
125136 std::vector Members;
137
126138 Group() : Section(SectionKind::Group) {}
139
127140 static bool classof(const Section *S) {
128141 return S->Kind == SectionKind::Group;
129142 }
135148 ELF_REL Type;
136149 StringRef Symbol;
137150 };
151
138152 struct RelocationSection : Section {
139153 std::vector Relocations;
154
140155 RelocationSection() : Section(SectionKind::Relocation) {}
156
141157 static bool classof(const Section *S) {
142158 return S->Kind == SectionKind::Relocation;
143159 }
156172 MIPS_AFL_ASE ASEs;
157173 MIPS_AFL_FLAGS1 Flags1;
158174 llvm::yaml::Hex32 Flags2;
175
159176 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
177
160178 static bool classof(const Section *S) {
161179 return S->Kind == SectionKind::MipsABIFlags;
162180 }
315333 } // end namespace yaml
316334 } // end namespace llvm
317335
318 #endif
336 #endif // LLVM_OBJECTYAML_ELFYAML_H
1515 #ifndef LLVM_OBJECTYAML_MACHOYAML_H
1616 #define LLVM_OBJECTYAML_MACHOYAML_H
1717
18 #include "llvm/ADT/StringRef.h"
1819 #include "llvm/BinaryFormat/MachO.h"
1920 #include "llvm/ObjectYAML/DWARFYAML.h"
20 #include "llvm/ObjectYAML/YAML.h"
21 #include "llvm/Support/YAMLTraits.h"
22 #include
23 #include
24 #include
2125
2226 namespace llvm {
2327 namespace MachOYAML {
5054
5155 struct LoadCommand {
5256 virtual ~LoadCommand();
57
5358 llvm::MachO::macho_load_command Data;
5459 std::vector
Sections;
5560 std::vector Tools;
6570 uint16_t n_desc;
6671 uint64_t n_value;
6772 };
73
6874 struct RebaseOpcode {
6975 MachO::RebaseOpcode Opcode;
7076 uint8_t Imm;
8086 };
8187
8288 struct ExportEntry {
83 ExportEntry()
84 : TerminalSize(0), NodeOffset(0), Name(), Flags(0), Address(0), Other(0),
85 ImportName(), Children() {}
86 uint64_t TerminalSize;
87 uint64_t NodeOffset;
89 uint64_t TerminalSize = 0;
90 uint64_t NodeOffset = 0;
8891 std::string Name;
89 llvm::yaml::Hex64 Flags;
90 llvm::yaml::Hex64 Address;
91 llvm::yaml::Hex64 Other;
92 llvm::yaml::Hex64 Flags = 0;
93 llvm::yaml::Hex64 Address = 0;
94 llvm::yaml::Hex64 Other = 0;
9295 std::string ImportName;
9396 std::vector Children;
9497 };
134137 std::vector Slices;
135138 };
136139
137 } // namespace llvm::MachOYAML
138 } // namespace llvm
140 } // end namespace MachOYAML
141 } // end namespace llvm
139142
140143 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
141144 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
148151 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachO::build_tool_version)
149152
150153 namespace llvm {
154
155 class raw_ostream;
156
151157 namespace yaml {
152158
153159 template <> struct MappingTraits {
249255 };
250256
251257 // This trait is used for 16-byte chars in Mach structures used for strings
252 typedef char char_16[16];
258 using char_16 = char[16];
253259
254260 template <> struct ScalarTraits {
255 static void output(const char_16 &Val, void *, llvm::raw_ostream &Out);
256
261 static void output(const char_16 &Val, void *, raw_ostream &Out);
257262 static StringRef input(StringRef Scalar, void *, char_16 &Val);
258263 static bool mustQuote(StringRef S);
259264 };
260265
261266 // This trait is used for UUIDs. It reads and writes them matching otool's
262267 // formatting style.
263 typedef uint8_t uuid_t[16];
268 using uuid_t = uint8_t[16];
264269
265270 template <> struct ScalarTraits {
266 static void output(const uuid_t &Val, void *, llvm::raw_ostream &Out);
267
271 static void output(const uuid_t &Val, void *, raw_ostream &Out);
268272 static StringRef input(StringRef Scalar, void *, uuid_t &Val);
269273 static bool mustQuote(StringRef S);
270274 };
295299 static void mapping(IO &IO, MachO::section_64 &LoadCommand);
296300 };
297301
298 } // namespace llvm::yaml
299
300 } // namespace llvm
301
302 #endif
302 } // end namespace yaml
303
304 } // end namespace llvm
305
306 #endif // LLVM_OBJECTYAML_MACHOYAML_H
1414 #include "llvm/ObjectYAML/MachOYAML.h"
1515 #include "llvm/ObjectYAML/WasmYAML.h"
1616 #include "llvm/Support/YAMLTraits.h"
17 #include
1718
1819 namespace llvm {
1920 namespace yaml {
21
22 class IO;
2023
2124 struct YamlObjectFile {
2225 std::unique_ptr Elf;
3033 static void mapping(IO &IO, YamlObjectFile &ObjectFile);
3134 };
3235
33 } // namespace yaml
34 } // namespace llvm
36 } // end namespace yaml
37 } // end namespace llvm
3538
36 #endif
39 #endif // LLVM_OBJECTYAML_OBJECTYAML_H
1515 #ifndef LLVM_OBJECTYAML_WASMYAML_H
1616 #define LLVM_OBJECTYAML_WASMYAML_H
1717
18 #include "llvm/ADT/StringRef.h"
1819 #include "llvm/BinaryFormat/Wasm.h"
1920 #include "llvm/ObjectYAML/YAML.h"
21 #include "llvm/Support/Casting.h"
22 #include
23 #include
24 #include
2025
2126 namespace llvm {
2227 namespace WasmYAML {
103108 };
104109
105110 struct Signature {
106 Signature() : Form(wasm::WASM_TYPE_FUNC) {}
107
108 uint32_t Index;
109 SignatureForm Form;
111 uint32_t Index;
112 SignatureForm Form = wasm::WASM_TYPE_FUNC;
110113 std::vector ParamTypes;
111114 ValueType ReturnType;
112115 };
127130 struct CustomSection : Section {
128131 explicit CustomSection(StringRef Name)
129132 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
133
130134 static bool classof(const Section *S) {
131135 return S->Type == wasm::WASM_SEC_CUSTOM;
132136 }
137141
138142 struct NameSection : CustomSection {
139143 NameSection() : CustomSection("name") {}
144
140145 static bool classof(const Section *S) {
141146 auto C = dyn_cast(S);
142147 return C && C->Name == "name";
147152
148153 struct LinkingSection : CustomSection {
149154 LinkingSection() : CustomSection("linking") {}
155
150156 static bool classof(const Section *S) {
151157 auto C = dyn_cast(S);
152158 return C && C->Name == "linking";
159165
160166 struct TypeSection : Section {
161167 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
168
162169 static bool classof(const Section *S) {
163170 return S->Type == wasm::WASM_SEC_TYPE;
164171 }
168175
169176 struct ImportSection : Section {
170177 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
178
171179 static bool classof(const Section *S) {
172180 return S->Type == wasm::WASM_SEC_IMPORT;
173181 }
177185
178186 struct FunctionSection : Section {
179187 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
188
180189 static bool classof(const Section *S) {
181190 return S->Type == wasm::WASM_SEC_FUNCTION;
182191 }
186195
187196 struct TableSection : Section {
188197 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
198
189199 static bool classof(const Section *S) {
190200 return S->Type == wasm::WASM_SEC_TABLE;
191201 }
195205
196206 struct MemorySection : Section {
197207 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
208
198209 static bool classof(const Section *S) {
199210 return S->Type == wasm::WASM_SEC_MEMORY;
200211 }
204215
205216 struct GlobalSection : Section {
206217 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
218
207219 static bool classof(const Section *S) {
208220 return S->Type == wasm::WASM_SEC_GLOBAL;
209221 }
213225
214226 struct ExportSection : Section {
215227 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
228
216229 static bool classof(const Section *S) {
217230 return S->Type == wasm::WASM_SEC_EXPORT;
218231 }
222235
223236 struct StartSection : Section {
224237 StartSection() : Section(wasm::WASM_SEC_START) {}
238
225239 static bool classof(const Section *S) {
226240 return S->Type == wasm::WASM_SEC_START;
227241 }
231245
232246 struct ElemSection : Section {
233247 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
248
234249 static bool classof(const Section *S) {
235250 return S->Type == wasm::WASM_SEC_ELEM;
236251 }
240255
241256 struct CodeSection : Section {
242257 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
258
243259 static bool classof(const Section *S) {
244260 return S->Type == wasm::WASM_SEC_CODE;
245261 }
249265
250266 struct DataSection : Section {
251267 DataSection() : Section(wasm::WASM_SEC_DATA) {}
268
252269 static bool classof(const Section *S) {
253270 return S->Type == wasm::WASM_SEC_DATA;
254271 }
378395 } // end namespace yaml
379396 } // end namespace llvm
380397
381 #endif
398 #endif // LLVM_OBJECTYAML_WASMYAML_H
99 #ifndef LLVM_OBJECTYAML_YAML_H
1010 #define LLVM_OBJECTYAML_YAML_H
1111
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
1214 #include "llvm/Support/YAMLTraits.h"
15 #include
1316
1417 namespace llvm {
18
19 class raw_ostream;
20
1521 namespace yaml {
22
1623 /// \brief Specialized YAMLIO scalar type for representing a binary blob.
1724 ///
1825 /// A typical use case would be to represent the content of a section in a
5562 /// \endcode
5663 class BinaryRef {
5764 friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS);
65
5866 /// \brief Either raw binary data, or a string of hex bytes (must always
5967 /// be an even number of characters).
6068 ArrayRef Data;
69
6170 /// \brief Discriminator between the two states of the `Data` member.
62 bool DataIsHexString;
71 bool DataIsHexString = true;
6372
6473 public:
74 BinaryRef() = default;
6575 BinaryRef(ArrayRef Data) : Data(Data), DataIsHexString(false) {}
6676 BinaryRef(StringRef Data)
67 : Data(reinterpret_cast(Data.data()), Data.size()),
68 DataIsHexString(true) {}
69 BinaryRef() : DataIsHexString(true) {}
77 : Data(reinterpret_cast(Data.data()), Data.size()) {}
78
7079 /// \brief The number of bytes that are represented by this BinaryRef.
7180 /// This is the number of bytes that writeAsBinary() will write.
7281 ArrayRef::size_type binary_size() const {
7483 return Data.size() / 2;
7584 return Data.size();
7685 }
86
7787 /// \brief Write the contents (regardless of whether it is binary or a
7888 /// hex string) as binary to the given raw_ostream.
7989 void writeAsBinary(raw_ostream &OS) const;
90
8091 /// \brief Write the contents (regardless of whether it is binary or a
8192 /// hex string) as hex to the given raw_ostream.
8293 ///
93104 }
94105
95106 template <> struct ScalarTraits {
96 static void output(const BinaryRef &, void *, llvm::raw_ostream &);
107 static void output(const BinaryRef &, void *, raw_ostream &);
97108 static StringRef input(StringRef, void *, BinaryRef &);
98109 static bool mustQuote(StringRef S) { return needsQuotes(S); }
99110 };
100 }
101 }
102 #endif
111
112 } // end namespace yaml
113
114 } // end namespace llvm
115
116 #endif // LLVM_OBJECTYAML_YAML_H
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/ObjectYAML/COFFYAML.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/YAMLTraits.h"
16 #include
17 #include
1418
1519 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
20
1621 namespace llvm {
1722
1823 namespace COFFYAML {
24
1925 Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
2026 Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
2127 Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
22 }
28
29 } // end namespace COFFYAML
2330
2431 namespace yaml {
32
2533 void ScalarEnumerationTraits::enumeration(
2634 IO &IO, COFFYAML::COMDATType &Value) {
2735 IO.enumCase(Value, "0", 0);
171179
172180 void ScalarEnumerationTraits::enumeration(
173181 IO &IO, COFF::WindowsSubsystem &Value) {
174 ECase(IMAGE_SUBSYSTEM_UNKNOWN);
175 ECase(IMAGE_SUBSYSTEM_NATIVE);
176 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
177 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
178 ECase(IMAGE_SUBSYSTEM_OS2_CUI);
179 ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
180 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
181 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
182 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
183 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
184 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
185 ECase(IMAGE_SUBSYSTEM_EFI_ROM);
186 ECase(IMAGE_SUBSYSTEM_XBOX);
187 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
182 ECase(IMAGE_SUBSYSTEM_UNKNOWN);
183 ECase(IMAGE_SUBSYSTEM_NATIVE);
184 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
185 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
186 ECase(IMAGE_SUBSYSTEM_OS2_CUI);
187 ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
188 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
189 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
190 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
191 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
192 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
193 ECase(IMAGE_SUBSYSTEM_EFI_ROM);
194 ECase(IMAGE_SUBSYSTEM_XBOX);
195 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
188196 }
189197 #undef ECase
190198
251259 #undef BCase
252260
253261 namespace {
262
254263 struct NSectionSelectionType {
255264 NSectionSelectionType(IO &)
256265 : SelectionType(COFFYAML::COMDATType(0)) {}
257266 NSectionSelectionType(IO &, uint8_t C)
258267 : SelectionType(COFFYAML::COMDATType(C)) {}
268
259269 uint8_t denormalize(IO &) { return SelectionType; }
270
260271 COFFYAML::COMDATType SelectionType;
261272 };
262273
265276 : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
266277 NWeakExternalCharacteristics(IO &, uint32_t C)
267278 : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
279
268280 uint32_t denormalize(IO &) { return Characteristics; }
281
269282 COFFYAML::WeakExternalCharacteristics Characteristics;
270283 };
271284
274287 : Characteristics(COFF::SectionCharacteristics(0)) {}
275288 NSectionCharacteristics(IO &, uint32_t C)
276289 : Characteristics(COFF::SectionCharacteristics(C)) {}
290
277291 uint32_t denormalize(IO &) { return Characteristics; }
292
278293 COFF::SectionCharacteristics Characteristics;
279294 };
280295
283298 : AuxType(COFFYAML::AuxSymbolType(0)) {}
284299 NAuxTokenType(IO &, uint8_t C)
285300 : AuxType(COFFYAML::AuxSymbolType(C)) {}
301
286302 uint32_t denormalize(IO &) { return AuxType; }
303
287304 COFFYAML::AuxSymbolType AuxType;
288305 };
289306
290307 struct NStorageClass {
291308 NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
292309 NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
310
293311 uint8_t denormalize(IO &) { return StorageClass; }
294312
295313 COFF::SymbolStorageClass StorageClass;
298316 struct NMachine {
299317 NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
300318 NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
319
301320 uint16_t denormalize(IO &) { return Machine; }
321
302322 COFF::MachineTypes Machine;
303323 };
304324
306326 NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
307327 NHeaderCharacteristics(IO &, uint16_t C)
308328 : Characteristics(COFF::Characteristics(C)) {}
329
309330 uint16_t denormalize(IO &) { return Characteristics; }
310331
311332 COFF::Characteristics Characteristics;
315336 struct NType {
316337 NType(IO &) : Type(RelocType(0)) {}
317338 NType(IO &, uint16_t T) : Type(RelocType(T)) {}
339
318340 uint16_t denormalize(IO &) { return Type; }
341
319342 RelocType Type;
320343 };
321344
322345 struct NWindowsSubsystem {
323346 NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
324347 NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
348
325349 uint16_t denormalize(IO &) { return Subsystem; }
326350
327351 COFF::WindowsSubsystem Subsystem;
331355 NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
332356 NDLLCharacteristics(IO &, uint16_t C)
333357 : Characteristics(COFF::DLLCharacteristics(C)) {}
358
334359 uint16_t denormalize(IO &) { return Characteristics; }
335360
336361 COFF::DLLCharacteristics Characteristics;
337362 };
338363
339 }
364 } // end anonymous namespace
340365
341366 void MappingTraits::mapping(IO &IO,
342367 COFFYAML::Relocation &Rel) {
508533 IO.mapRequired("symbols", Obj.Symbols);
509534 }
510535
511 }
512 }
536 } // end namespace yaml
537
538 } // end namespace llvm
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
15
15 #include "llvm/ADT/STLExtras.h"
1616 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/COFF.h"
19 #include "llvm/DebugInfo/CodeView/CodeView.h"
1820 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
1921 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
2022 #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
2325 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
2426 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
2527 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
28 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
2629 #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h"
2730 #include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h"
2831 #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
29 #include "llvm/DebugInfo/CodeView/EnumTables.h"
32 #include "llvm/DebugInfo/CodeView/Line.h"
3033 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
31 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
32 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
34 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
3335 #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
34 #include "llvm/Support/BinaryStreamWriter.h"
36 #include "llvm/Support/Allocator.h"
37 #include "llvm/Support/BinaryStreamReader.h"
38 #include "llvm/Support/Endian.h"
39 #include "llvm/Support/Error.h"
40 #include "llvm/Support/ErrorHandling.h"
41 #include "llvm/Support/YAMLTraits.h"
42 #include "llvm/Support/raw_ostream.h"
43 #include
44 #include
45 #include
46 #include
47 #include
48 #include
49 #include
50
3551 using namespace llvm;
3652 using namespace llvm::codeview;
3753 using namespace llvm::CodeViewYAML;
6783 namespace llvm {
6884 namespace CodeViewYAML {
6985 namespace detail {
86
7087 struct YAMLSubsectionBase {
7188 explicit YAMLSubsectionBase(DebugSubsectionKind Kind) : Kind(Kind) {}
72 DebugSubsectionKind Kind;
73 virtual ~YAMLSubsectionBase() {}
89 virtual ~YAMLSubsectionBase() = default;
7490
7591 virtual void map(IO &IO) = 0;
7692 virtual std::shared_ptr
7793 toCodeViewSubsection(BumpPtrAllocator &Allocator,
7894 const codeview::StringsAndChecksums &SC) const = 0;
79 };
80 }
81 }
82 }
95
96 DebugSubsectionKind Kind;
97 };
98
99 } // end namespace detail
100 } // end namespace CodeViewYAML
101 } // end namespace llvm
83102
84103 namespace {
104
85105 struct YAMLChecksumsSubsection : public YAMLSubsectionBase {
86106 YAMLChecksumsSubsection()
87107 : YAMLSubsectionBase(DebugSubsectionKind::FileChecksums) {}
212232
213233 std::vector RVAs;
214234 };
215 }
235
236 } // end anonymous namespace
216237
217238 void ScalarBitSetTraits::bitset(IO &io, LineFlags &Flags) {
218239 io.bitSetCase(Flags, "HasColumnInfo", LF_HaveColumns);
740761 }
741762
742763 namespace {
764
743765 struct SubsectionConversionVisitor : public DebugSubsectionVisitor {
744 SubsectionConversionVisitor() {}
766 SubsectionConversionVisitor() = default;
745767
746768 Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override;
747769 Error visitLines(DebugLinesSubsectionRef &Lines,
766788 YAMLDebugSubsection Subsection;
767789 };
768790
791 } // end anonymous namespace
792
769793 Error SubsectionConversionVisitor::visitUnknown(
770794 DebugUnknownSubsectionRef &Unknown) {
771795 return make_error(cv_error_code::operation_unsupported);
862886 Subsection.Subsection = *Result;
863887 return Error::success();
864888 }
865 }
866889
867890 Expected
868891 YAMLDebugSubsection::fromCodeViewSubection(const StringsAndChecksumsRef &SC,
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/DebugInfo/CodeView/CodeView.h"
1818 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
1919 #include "llvm/DebugInfo/CodeView/EnumTables.h"
20 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
2021 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
22 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
2123 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
24 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
25 #include "llvm/ObjectYAML/YAML.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Error.h"
28 #include "llvm/Support/YAMLTraits.h"
29 #include
30 #include
31 #include
32 #include
33 #include
2234
2335 using namespace llvm;
2436 using namespace llvm::codeview;
4759 LLVM_YAML_DECLARE_ENUM_TRAITS(TrampolineType)
4860 LLVM_YAML_DECLARE_ENUM_TRAITS(ThunkOrdinal)
4961
50 LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, TypeName)
62 LLVM_YAML_STRONG_TYPEDEF(StringRef, TypeName)
5163
5264 LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeName, true)
5365
5466 StringRef ScalarTraits::input(StringRef S, void *V, TypeName &T) {
5567 return ScalarTraits::input(S, V, T.value);
5668 }
69
5770 void ScalarTraits::output(const TypeName &T, void *V,
58 llvm::raw_ostream &R) {
71 raw_ostream &R) {
5972 ScalarTraits::output(T.value, V, R);
6073 }
6174
172185
173186 struct SymbolRecordBase {
174187 codeview::SymbolKind Kind;
188
175189 explicit SymbolRecordBase(codeview::SymbolKind K) : Kind(K) {}
176
177 virtual ~SymbolRecordBase() {}
190 virtual ~SymbolRecordBase() = default;
191
178192 virtual void map(yaml::IO &io) = 0;
179193 virtual codeview::CVSymbol
180194 toCodeViewSymbol(BumpPtrAllocator &Allocator,
193207 CodeViewContainer Container) const override {
194208 return SymbolSerializer::writeOneSymbol(Symbol, Allocator, Container);
195209 }
210
196211 Error fromCodeViewSymbol(codeview::CVSymbol CVS) override {
197212 return SymbolDeserializer::deserializeAs(CVS, Symbol);
198213 }
216231 ::memcpy(Buffer + sizeof(RecordPrefix), Data.data(), Data.size());
217232 return CVSymbol(Kind, ArrayRef(Buffer, TotalLen));
218233 }
234
219235 Error fromCodeViewSymbol(CVSymbol CVS) override {
220236 this->Kind = CVS.kind();
221237 Data = CVS.RecordData.drop_front(sizeof(RecordPrefix));
495511 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
496512 IO.mapRequired("DisplayName", Symbol.Name);
497513 }
498 }
499 }
500 }
514
515 } // end namespace detail
516 } // end namespace CodeViewYAML
517 } // end namespace llvm
501518
502519 CVSymbol CodeViewYAML::SymbolRecord::toCodeViewSymbol(
503520 BumpPtrAllocator &Allocator, CodeViewContainer Container) const {
506523
507524 namespace llvm {
508525 namespace yaml {
526
509527 template <> struct MappingTraits {
510528 static void mapping(IO &io, SymbolRecordBase &Record) { Record.map(io); }
511529 };
512 }
513 }
530
531 } // end namespace yaml
532 } // end namespace llvm
514533
515534 template
516535 static inline Expected
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/ADT/APSInt.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/COFF.h"
1719 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
20 #include "llvm/DebugInfo/CodeView/CodeView.h"
1821 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
19 #include "llvm/DebugInfo/CodeView/EnumTables.h"
2022 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
23 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
2124 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
25 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/BinaryStreamReader.h"
2228 #include "llvm/Support/BinaryStreamWriter.h"
29 #include "llvm/Support/Endian.h"
30 #include "llvm/Support/Error.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/YAMLTraits.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include
35 #include
36 #include
37 #include
2338
2439 using namespace llvm;
2540 using namespace llvm::codeview;
6176
6277 struct LeafRecordBase {
6378 TypeLeafKind Kind;
79
6480 explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {}
65
66 virtual ~LeafRecordBase() {}
81 virtual ~LeafRecordBase() = default;
82
6783 virtual void map(yaml::IO &io) = 0;
6884 virtual CVType toCodeViewRecord(TypeTableBuilder &TTB) const = 0;
6985 virtual Error fromCodeViewRecord(CVType Type) = 0;
99115
100116 struct MemberRecordBase {
101117 TypeLeafKind Kind;
118
102119 explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {}
103
104 virtual ~MemberRecordBase() {}
120 virtual ~MemberRecordBase() = default;
121
105122 virtual void map(yaml::IO &io) = 0;
106123 virtual void writeTo(FieldListRecordBuilder &FLRB) = 0;
107124 };
109126 template struct MemberRecordImpl : public MemberRecordBase {
110127 explicit MemberRecordImpl(TypeLeafKind K)
111128 : MemberRecordBase(K), Record(static_cast(K)) {}
129
112130 void map(yaml::IO &io) override;
113131
114132 void writeTo(FieldListRecordBuilder &FLRB) override {
117135
118136 mutable T Record;
119137 };
120 }
121 }
122 }
138
139 } // end namespace detail
140 } // end namespace CodeViewYAML
141 } // end namespace llvm
123142
124143 void ScalarTraits::output(const TypeIndex &S, void *,
125 llvm::raw_ostream &OS) {
144 raw_ostream &OS) {
126145 OS << S.getIndex();
127146 }
128147
134153 return Result;
135154 }
136155
137 void ScalarTraits::output(const APSInt &S, void *,
138 llvm::raw_ostream &OS) {
156 void ScalarTraits::output(const APSInt &S, void *, raw_ostream &OS) {
139157 S.print(OS, S.isSigned());
140158 }
141159
344362 namespace llvm {
345363 namespace CodeViewYAML {
346364 namespace detail {
365
347366 template <> void LeafRecordImpl::map(IO &IO) {
348367 IO.mapRequired("ModifiedType", Record.ModifiedType);
349368 IO.mapRequired("Modifiers", Record.Modifiers);
402421 void LeafRecordImpl::map(IO &IO) {
403422 IO.mapRequired("FieldList", Members);
404423 }
405 }
406 }
407 }
424
425 } // end namespace detail
426 } // end namespace CodeViewYAML
427 } // end namespace llvm
408428
409429 namespace {
430
410431 class MemberRecordConversionVisitor : public TypeVisitorCallbacks {
411432 public:
412433 explicit MemberRecordConversionVisitor(std::vector &Records)
431452
432453 std::vector &Records;
433454 };
434 }
455
456 } // end anonymous namespace
435457
436458 Error LeafRecordImpl::fromCodeViewRecord(CVType Type) {
437459 MemberRecordConversionVisitor V(Members);
459481 namespace llvm {
460482 namespace CodeViewYAML {
461483 namespace detail {
484
462485 template <> void LeafRecordImpl::map(IO &IO) {
463486 IO.mapRequired("MemberCount", Record.MemberCount);
464487 IO.mapRequired("Options", Record.Options);
465488 IO.mapRequired("FieldList", Record.FieldList);
466489 IO.mapRequired("Name", Record.Name);
467490 IO.mapRequired("UniqueName", Record.UniqueName);
468
469491 IO.mapRequired("DerivationList", Record.DerivationList);
470492 IO.mapRequired("VTableShape", Record.VTableShape);
471493 IO.mapRequired("Size", Record.Size);
477499 IO.mapRequired("FieldList", Record.FieldList);
478500 IO.mapRequired("Name", Record.Name);
479501 IO.mapRequired("UniqueName", Record.UniqueName);
480
481502 IO.mapRequired("Size", Record.Size);
482503 }
483504
487508 IO.mapRequired("FieldList", Record.FieldList);
488509 IO.mapRequired("Name", Record.Name);
489510 IO.mapRequired("UniqueName", Record.UniqueName);
490
491511 IO.mapRequired("UnderlyingType", Record.UnderlyingType);
492512 }
493513
601621 template <> void MemberRecordImpl::map(IO &IO) {
602622 IO.mapRequired("ContinuationIndex", Record.ContinuationIndex);
603623 }
604 }
605 }
606 }
624
625 } // end namespace detail
626 } // end namespace CodeViewYAML
627 } // end namespace llvm
607628
608629 template
609630 static inline Expected fromCodeViewRecordImpl(CVType Type) {
626647 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
627648 switch (Type.kind()) {
628649 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
629 default: { llvm_unreachable("Unknown leaf kind!"); }
650 default:
651 llvm_unreachable("Unknown leaf kind!");
630652 }
631653 return make_error(cv_error_code::corrupt_record);
632654 }
642664
643665 namespace llvm {
644666 namespace yaml {
667
645668 template <> struct MappingTraits {
646669 static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); }
647670 };
649672 template <> struct MappingTraits {
650673 static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); }
651674 };
652 }
653 }
675
676 } // end namespace yaml
677 } // end namespace llvm
654678
655679 template
656680 static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ObjectYAML/DWARFEmitter.h"
15 #include "DWARFVisitor.h"
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/ADT/StringRef.h"
1518 #include "llvm/ObjectYAML/DWARFYAML.h"
1619 #include "llvm/Support/Error.h"
20 #include "llvm/Support/Host.h"
1721 #include "llvm/Support/LEB128.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/MemoryBuffer.h"
1824 #include "llvm/Support/SwapByteOrder.h"
25 #include "llvm/Support/YAMLTraits.h"
1926 #include "llvm/Support/raw_ostream.h"
20
21 #include "DWARFVisitor.h"
22
2327 #include
28 #include
29 #include
30 #include
31 #include
32 #include
33 #include
2434
2535 using namespace llvm;
2636
126136 raw_ostream &OS;
127137
128138 protected:
129 virtual void onStartCompileUnit(const DWARFYAML::Unit &CU) {
139 void onStartCompileUnit(const DWARFYAML::Unit &CU) override {
130140 writeInitialLength(CU.Length, OS, DebugInfo.IsLittleEndian);
131141 writeInteger((uint16_t)CU.Version, OS, DebugInfo.IsLittleEndian);
132142 if(CU.Version >= 5) {
140150
141151 }
142152
143 virtual void onStartDIE(const DWARFYAML::Unit &CU,
144 const DWARFYAML::Entry &DIE) {
153 void onStartDIE(const DWARFYAML::Unit &CU,
154 const DWARFYAML::Entry &DIE) override {
145155 encodeULEB128(DIE.AbbrCode, OS);
146156 }
147157
148 virtual void onValue(const uint8_t U) {
158 void onValue(const uint8_t U) override {
149159 writeInteger(U, OS, DebugInfo.IsLittleEndian);
150160 }
151161
152 virtual void onValue(const uint16_t U) {
162 void onValue(const uint16_t U) override {
153163 writeInteger(U, OS, DebugInfo.IsLittleEndian);
154164 }
155 virtual void onValue(const uint32_t U) {
165
166 void onValue(const uint32_t U) override {
156167 writeInteger(U, OS, DebugInfo.IsLittleEndian);
157168 }
158 virtual void onValue(const uint64_t U, const bool LEB = false) {
169
170 void onValue(const uint64_t U, const bool LEB = false) override {
159171 if (LEB)
160172 encodeULEB128(U, OS);
161173 else
162174 writeInteger(U, OS, DebugInfo.IsLittleEndian);
163175 }
164176
165 virtual void onValue(const int64_t S, const bool LEB = false) {
177 void onValue(const int64_t S, const bool LEB = false) override {
166178 if (LEB)
167179 encodeSLEB128(S, OS);
168180 else
169181 writeInteger(S, OS, DebugInfo.IsLittleEndian);
170182 }
171183
172 virtual void onValue(const StringRef String) {
184 void onValue(const StringRef String) override {
173185 OS.write(String.data(), String.size());
174186 OS.write('\0');
175187 }
176188
177 virtual void onValue(const MemoryBufferRef MBR) {
189 void onValue(const MemoryBufferRef MBR) override {
178190 OS.write(MBR.getBufferStart(), MBR.getBufferSize());
179191 }
180192
279291 }
280292 }
281293
282 typedef void (*EmitFuncType)(raw_ostream &, const DWARFYAML::Data &);
294 using EmitFuncType = void (*)(raw_ostream &, const DWARFYAML::Data &);
283295
284296 static void
285297 EmitDebugSectionImpl(const DWARFYAML::Data &DI, EmitFuncType EmitFunc,
170170 IO.mapRequired("TotalLength64", InitialLength.TotalLength64);
171171 }
172172
173 } // namespace llvm::yaml
173 } // end namespace yaml
174174
175 } // namespace llvm
175 } // end namespace llvm
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/ObjectYAML/ELFYAML.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/ELF.h"
1416 #include "llvm/Support/Casting.h"
17 #include "llvm/Support/ErrorHandling.h"
1518 #include "llvm/Support/MipsABIFlags.h"
19 #include "llvm/Support/YAMLTraits.h"
20 #include
21 #include
1622
1723 namespace llvm {
1824
19 ELFYAML::Section::~Section() {}
25 ELFYAML::Section::~Section() = default;
2026
2127 namespace yaml {
2228
643649 }
644650
645651 namespace {
652
646653 struct NormalizedOther {
647654 NormalizedOther(IO &)
648655 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
654661 ELFYAML::ELF_STV Visibility;
655662 ELFYAML::ELF_STO Other;
656663 };
657 }
664
665 } // end anonymous namespace
658666
659667 void MappingTraits::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
660668 IO.mapOptional("Name", Symbol.Name, StringRef());
777785 }
778786
779787 namespace {
788
780789 struct NormalizedMips64RelType {
781790 NormalizedMips64RelType(IO &)
782791 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
797806 ELFYAML::ELF_REL Type3;
798807 ELFYAML::ELF_RSS SpecSym;
799808 };
800 }
809
810 } // end anonymous namespace
801811
802812 void MappingTraits::mapping(IO &IO,
803813 ELFYAML::Relocation &Rel) {
838848 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
839849
840850 } // end namespace yaml
851
841852 } // end namespace llvm
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/ObjectYAML/MachOYAML.h"
14 #include "llvm/ADT/StringRef.h"
1415 #include "llvm/BinaryFormat/MachO.h"
15 #include "llvm/Support/Casting.h"
1616 #include "llvm/Support/Format.h"
1717 #include "llvm/Support/Host.h"
18
19 #include // For memcpy, memset and strnlen.
18 #include "llvm/Support/YAMLTraits.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include
21 #include
22 #include
2023
2124 namespace llvm {
2225
23 MachOYAML::LoadCommand::~LoadCommand() {}
26 MachOYAML::LoadCommand::~LoadCommand() = default;
2427
2528 bool MachOYAML::LinkEditData::isEmpty() const {
2629 return 0 ==
3235 namespace yaml {
3336
3437 void ScalarTraits::output(const char_16 &Val, void *,
35 llvm::raw_ostream &Out) {
38 raw_ostream &Out) {
3639 auto Len = strnlen(&Val[0], 16);
3740 Out << StringRef(&Val[0], Len);
3841 }
5053
5154 bool ScalarTraits::mustQuote(StringRef S) { return needsQuotes(S); }
5255
53 void ScalarTraits::output(const uuid_t &Val, void *,
54 llvm::raw_ostream &Out) {
56 void ScalarTraits::output(const uuid_t &Val, void *, raw_ostream &Out) {
5557 for (int Idx = 0; Idx < 16; ++Idx) {
5658 Out << format("%02" PRIX32, Val[Idx]);
5759 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
153155 IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
154156 IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
155157 IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
156 if(LinkEditData.ExportTrie.Children.size() > 0 || !IO.outputting())
158 if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
157159 IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
158160 IO.mapOptional("NameList", LinkEditData.NameList);
159161 IO.mapOptional("StringTable", LinkEditData.StringTable);
307309
308310 void MappingTraits::mapping(
309311 IO &IO, MachO::dylinker_command &LoadCommand) {
310
311312 IO.mapRequired("name", LoadCommand.name);
312313 }
313314
314315 void MappingTraits::mapping(
315316 IO &IO, MachO::dysymtab_command &LoadCommand) {
316
317317 IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
318318 IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
319319 IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
336336
337337 void MappingTraits::mapping(
338338 IO &IO, MachO::encryption_info_command &LoadCommand) {
339
340339 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
341340 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
342341 IO.mapRequired("cryptid", LoadCommand.cryptid);
344343
345344 void MappingTraits::mapping(
346345 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
347
348346 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
349347 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
350348 IO.mapRequired("cryptid", LoadCommand.cryptid);
353351
354352 void MappingTraits::mapping(
355353 IO &IO, MachO::entry_point_command &LoadCommand) {
356
357354 IO.mapRequired("entryoff", LoadCommand.entryoff);
358355 IO.mapRequired("stacksize", LoadCommand.stacksize);
359356 }
360357
361358 void MappingTraits::mapping(
362359 IO &IO, MachO::fvmfile_command &LoadCommand) {
363
364360 IO.mapRequired("name", LoadCommand.name);
365361 IO.mapRequired("header_addr", LoadCommand.header_addr);
366362 }
373369
374370 void MappingTraits::mapping(
375371 IO &IO, MachO::fvmlib_command &LoadCommand) {
376
377372 IO.mapRequired("fvmlib", LoadCommand.fvmlib);
378373 }
379374
382377
383378 void MappingTraits::mapping(
384379 IO &IO, MachO::linkedit_data_command &LoadCommand) {
385
386380 IO.mapRequired("dataoff", LoadCommand.dataoff);
387381 IO.mapRequired("datasize", LoadCommand.datasize);
388382 }
389383
390384 void MappingTraits::mapping(
391385 IO &IO, MachO::linker_option_command &LoadCommand) {
392
393386 IO.mapRequired("count", LoadCommand.count);
394387 }
395388
396389 void MappingTraits::mapping(
397390 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
398
399391 IO.mapRequired("cksum", LoadCommand.cksum);
400392 }
401393
404396
405397 void MappingTraits::mapping(
406398 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
407
408399 IO.mapRequired("name", LoadCommand.name);
409400 IO.mapRequired("nmodules", LoadCommand.nmodules);
410401 IO.mapRequired("linked_modules", LoadCommand.linked_modules);
412403
413404 void MappingTraits::mapping(
414405 IO &IO, MachO::routines_command &LoadCommand) {
415
416406 IO.mapRequired("init_address", LoadCommand.init_address);
417407 IO.mapRequired("init_module", LoadCommand.init_module);
418408 IO.mapRequired("reserved1", LoadCommand.reserved1);
425415
426416 void MappingTraits::mapping(
427417 IO &IO, MachO::routines_command_64 &LoadCommand) {
428
429418 IO.mapRequired("init_address", LoadCommand.init_address);
430419 IO.mapRequired("init_module", LoadCommand.init_module);
431420 IO.mapRequired("reserved1", LoadCommand.reserved1);
438427
439428 void MappingTraits::mapping(
440429 IO &IO, MachO::rpath_command &LoadCommand) {
441
442430 IO.mapRequired("path", LoadCommand.path);
443431 }
444432
474462
475463 void MappingTraits::mapping(
476464 IO &IO, MachO::segment_command &LoadCommand) {
477
478465 IO.mapRequired("segname", LoadCommand.segname);
479466 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
480467 IO.mapRequired("vmsize", LoadCommand.vmsize);
488475
489476 void MappingTraits::mapping(
490477 IO &IO, MachO::segment_command_64 &LoadCommand) {
491
492478 IO.mapRequired("segname", LoadCommand.segname);
493479 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
494480 IO.mapRequired("vmsize", LoadCommand.vmsize);
502488
503489 void MappingTraits::mapping(
504490 IO &IO, MachO::source_version_command &LoadCommand) {
505
506491 IO.mapRequired("version", LoadCommand.version);
507492 }
508493
509494 void MappingTraits::mapping(
510495 IO &IO, MachO::sub_client_command &LoadCommand) {
511
512496 IO.mapRequired("client", LoadCommand.client);
513497 }
514498
515499 void MappingTraits::mapping(
516500 IO &IO, MachO::sub_framework_command &LoadCommand) {
517
518501 IO.mapRequired("umbrella", LoadCommand.umbrella);
519502 }
520503
521504 void MappingTraits::mapping(
522505 IO &IO, MachO::sub_library_command &LoadCommand) {
523
524506 IO.mapRequired("sub_library", LoadCommand.sub_library);
525507 }
526508
527509 void MappingTraits::mapping(
528510 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
529
530511 IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
531512 }
532513
533514 void MappingTraits::mapping(
534515 IO &IO, MachO::symseg_command &LoadCommand) {
535
536516 IO.mapRequired("offset", LoadCommand.offset);
537517 IO.mapRequired("size", LoadCommand.size);
538518 }
539519
540520 void MappingTraits::mapping(
541521 IO &IO, MachO::symtab_command &LoadCommand) {
542
543522 IO.mapRequired("symoff", LoadCommand.symoff);
544523 IO.mapRequired("nsyms", LoadCommand.nsyms);
545524 IO.mapRequired("stroff", LoadCommand.stroff);
551530
552531 void MappingTraits::mapping(
553532 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
554
555533 IO.mapRequired("offset", LoadCommand.offset);
556534 IO.mapRequired("nhints", LoadCommand.nhints);
557535 }
558536
559537 void MappingTraits::mapping(
560538 IO &IO, MachO::uuid_command &LoadCommand) {
561
562539 IO.mapRequired("uuid", LoadCommand.uuid);
563540 }
564541
565542 void MappingTraits::mapping(
566543 IO &IO, MachO::version_min_command &LoadCommand) {
567
568544 IO.mapRequired("version", LoadCommand.version);
569545 IO.mapRequired("sdk", LoadCommand.sdk);
570546 }
571547
572548 void MappingTraits::mapping(
573549 IO &IO, MachO::note_command &LoadCommand) {
574
575550 IO.mapRequired("data_owner", LoadCommand.data_owner);
576551 IO.mapRequired("offset", LoadCommand.offset);
577552 IO.mapRequired("size", LoadCommand.size);
579554
580555 void MappingTraits::mapping(
581556 IO &IO, MachO::build_version_command &LoadCommand) {
582
583557 IO.mapRequired("platform", LoadCommand.platform);
584558 IO.mapRequired("minos", LoadCommand.minos);
585559 IO.mapRequired("sdk", LoadCommand.sdk);
586560 IO.mapRequired("ntools", LoadCommand.ntools);
587561 }
588562
589 } // namespace llvm::yaml
590
591 } // namespace llvm
563 } // end namespace yaml
564
565 } // end namespace llvm
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/ObjectYAML/ObjectYAML.h"
14 #include "llvm/ObjectYAML/YAML.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/YAMLParser.h"
16 #include "llvm/Support/YAMLTraits.h"
17 #include
1518
1619 using namespace llvm;
1720 using namespace yaml;
5255 IO.setError("YAML Object File missing document type tag!");
5356 else
5457 IO.setError(
55 llvm::Twine("YAML Object File unsupported document type tag '") +
56 llvm::Twine(Tag) + llvm::Twine("'!"));
58 Twine("YAML Object File unsupported document type tag '") +
59 Twine(Tag) + Twine("'!"));
5760 }
5861 }
5962 }
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/ObjectYAML/WasmYAML.h"
14 #include "llvm/Object/Wasm.h"
14 #include "llvm/ADT/StringRef.h"
1515 #include "llvm/Support/Casting.h"
16 #include "llvm/Support/MipsABIFlags.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/YAMLTraits.h"
1718
1819 namespace llvm {
1920
2122
2223 // Declared here rather than in the header to comply with:
2324 // http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers
24 Section::~Section() {}
25 Section::~Section() = default;
2526
2627 } // end namespace WasmYAML
2728
404405 }
405406
406407 } // end namespace yaml
408
407409 } // end namespace llvm
1515 #include "llvm/ADT/StringExtras.h"
1616 #include "llvm/Support/raw_ostream.h"
1717 #include
18 #include
1819
1920 using namespace llvm;
2021
2122 void yaml::ScalarTraits::output(
22 const yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
23 const yaml::BinaryRef &Val, void *, raw_ostream &Out) {
2324 Val.writeAsHex(Out);
2425 }
2526
3334 if (!isxdigit(Scalar[I]))
3435 return "BinaryRef hex string must contain only hex digits.";
3536 Val = yaml::BinaryRef(Scalar);
36 return StringRef();
37 return {};
3738 }
3839
3940 void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {