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_OBJECT_COFFYAML_H
15 #define LLVM_OBJECT_COFFYAML_H
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/MC/YAML.h"
19 #include "llvm/Support/COFF.h"
24 inline Characteristics operator|(Characteristics a, Characteristics b) {
25 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
26 return static_cast<Characteristics>(Ret);
29 inline SectionCharacteristics operator|(SectionCharacteristics a,
30 SectionCharacteristics b) {
31 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
32 return static_cast<SectionCharacteristics>(Ret);
35 inline DLLCharacteristics operator|(DLLCharacteristics a,
36 DLLCharacteristics b) {
37 uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
38 return static_cast<DLLCharacteristics>(Ret);
42 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
43 // to use yaml::IO, we use these structures which are closer to the source.
45 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
46 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
47 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
50 uint32_t VirtualAddress;
58 yaml::BinaryRef SectionData;
59 std::vector<Relocation> Relocations;
66 COFF::SymbolBaseType SimpleType;
67 COFF::SymbolComplexType ComplexType;
68 Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
69 Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
70 Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
72 Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
73 Optional<COFF::AuxiliaryCLRToken> CLRToken;
79 COFF::PE32Header Header;
80 Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
84 Optional<PEHeader> OptionalHeader;
86 std::vector<Section> Sections;
87 std::vector<Symbol> Symbols;
93 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
94 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
95 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
101 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
102 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
106 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
107 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
111 struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
112 static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
116 struct ScalarEnumerationTraits<COFF::MachineTypes> {
117 static void enumeration(IO &IO, COFF::MachineTypes &Value);
121 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
122 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
126 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
127 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
131 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
132 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
136 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
137 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
141 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
142 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
146 struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
147 static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
151 struct ScalarBitSetTraits<COFF::Characteristics> {
152 static void bitset(IO &IO, COFF::Characteristics &Value);
156 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
157 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
161 struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
162 static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
166 struct MappingTraits<COFFYAML::Relocation> {
167 static void mapping(IO &IO, COFFYAML::Relocation &Rel);
171 struct MappingTraits<COFFYAML::PEHeader> {
172 static void mapping(IO &IO, COFFYAML::PEHeader &PH);
176 struct MappingTraits<COFF::DataDirectory> {
177 static void mapping(IO &IO, COFF::DataDirectory &DD);
181 struct MappingTraits<COFF::header> {
182 static void mapping(IO &IO, COFF::header &H);
185 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
186 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
189 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
190 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
193 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
194 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
197 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
198 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
201 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
202 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
206 struct MappingTraits<COFFYAML::Symbol> {
207 static void mapping(IO &IO, COFFYAML::Symbol &S);
211 struct MappingTraits<COFFYAML::Section> {
212 static void mapping(IO &IO, COFFYAML::Section &Sec);
216 struct MappingTraits<COFFYAML::Object> {
217 static void mapping(IO &IO, COFFYAML::Object &Obj);
220 } // end namespace yaml
221 } // end namespace llvm