1 //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares classes for handling the YAML representation of COFF.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECTYAML_COFFYAML_H
15 #define LLVM_OBJECTYAML_COFFYAML_H
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/COFF.h"
20 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
21 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
22 #include "llvm/ObjectYAML/YAML.h"
30 inline Characteristics operator|(Characteristics a, Characteristics b) {
31 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
32 return static_cast<Characteristics>(Ret);
35 inline SectionCharacteristics operator|(SectionCharacteristics a,
36 SectionCharacteristics b) {
37 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
38 return static_cast<SectionCharacteristics>(Ret);
41 inline DLLCharacteristics operator|(DLLCharacteristics a,
42 DLLCharacteristics b) {
43 uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
44 return static_cast<DLLCharacteristics>(Ret);
47 } // end namespace COFF
49 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
50 // to use yaml::IO, we use these structures which are closer to the source.
53 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
54 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
55 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
58 uint32_t VirtualAddress;
65 unsigned Alignment = 0;
66 yaml::BinaryRef SectionData;
67 std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
68 std::vector<CodeViewYAML::LeafRecord> DebugT;
69 std::vector<Relocation> Relocations;
77 COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
78 COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
79 Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
80 Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
81 Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
83 Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
84 Optional<COFF::AuxiliaryCLRToken> CLRToken;
91 COFF::PE32Header Header;
92 Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
96 Optional<PEHeader> OptionalHeader;
98 std::vector<Section> Sections;
99 std::vector<Symbol> Symbols;
104 } // end namespace COFFYAML
106 } // end namespace llvm
108 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
109 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
110 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
116 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
117 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
121 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
122 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
126 struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
127 static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
131 struct ScalarEnumerationTraits<COFF::MachineTypes> {
132 static void enumeration(IO &IO, COFF::MachineTypes &Value);
136 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
137 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
141 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
142 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
146 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
147 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
151 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
152 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
156 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
157 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
161 struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
162 static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
166 struct ScalarBitSetTraits<COFF::Characteristics> {
167 static void bitset(IO &IO, COFF::Characteristics &Value);
171 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
172 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
176 struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
177 static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
181 struct MappingTraits<COFFYAML::Relocation> {
182 static void mapping(IO &IO, COFFYAML::Relocation &Rel);
186 struct MappingTraits<COFFYAML::PEHeader> {
187 static void mapping(IO &IO, COFFYAML::PEHeader &PH);
191 struct MappingTraits<COFF::DataDirectory> {
192 static void mapping(IO &IO, COFF::DataDirectory &DD);
196 struct MappingTraits<COFF::header> {
197 static void mapping(IO &IO, COFF::header &H);
200 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
201 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
204 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
205 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
208 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
209 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
212 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
213 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
216 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
217 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
221 struct MappingTraits<COFFYAML::Symbol> {
222 static void mapping(IO &IO, COFFYAML::Symbol &S);
226 struct MappingTraits<COFFYAML::Section> {
227 static void mapping(IO &IO, COFFYAML::Section &Sec);
231 struct MappingTraits<COFFYAML::Object> {
232 static void mapping(IO &IO, COFFYAML::Object &Obj);
235 } // end namespace yaml
236 } // end namespace llvm
238 #endif // LLVM_OBJECTYAML_COFFYAML_H