1 //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares classes for handling the YAML representation of COFF. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_OBJECT_COFFYAML_H 15 #define LLVM_OBJECT_COFFYAML_H 16 17 #include "llvm/ADT/Optional.h" 18 #include "llvm/MC/YAML.h" 19 #include "llvm/Support/COFF.h" 20 21 namespace llvm { 22 23 namespace COFF { 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); 27 } 28 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); 33 } 34 } 35 36 // The structure of the yaml files is not an exact 1:1 match to COFF. In order 37 // to use yaml::IO, we use these structures which are closer to the source. 38 namespace COFFYAML { 39 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType) 40 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics) 41 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType) 42 43 struct Relocation { 44 uint32_t VirtualAddress; 45 uint16_t Type; 46 StringRef SymbolName; 47 }; 48 49 struct Section { 50 COFF::section Header; 51 unsigned Alignment; 52 yaml::BinaryRef SectionData; 53 std::vector<Relocation> Relocations; 54 StringRef Name; 55 Section(); 56 }; 57 58 struct Symbol { 59 COFF::symbol Header; 60 COFF::SymbolBaseType SimpleType; 61 COFF::SymbolComplexType ComplexType; 62 Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition; 63 Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol; 64 Optional<COFF::AuxiliaryWeakExternal> WeakExternal; 65 StringRef File; 66 Optional<COFF::AuxiliarySectionDefinition> SectionDefinition; 67 Optional<COFF::AuxiliaryCLRToken> CLRToken; 68 StringRef Name; 69 Symbol(); 70 }; 71 72 struct Object { 73 COFF::header Header; 74 std::vector<Section> Sections; 75 std::vector<Symbol> Symbols; 76 Object(); 77 }; 78 } 79 } 80 81 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section) 82 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol) 83 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation) 84 85 namespace llvm { 86 namespace yaml { 87 88 template <> 89 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> { 90 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value); 91 }; 92 93 template <> 94 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> { 95 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value); 96 }; 97 98 template <> 99 struct ScalarEnumerationTraits<COFFYAML::COMDATType> { 100 static void enumeration(IO &IO, COFFYAML::COMDATType &Value); 101 }; 102 103 template <> 104 struct ScalarEnumerationTraits<COFF::MachineTypes> { 105 static void enumeration(IO &IO, COFF::MachineTypes &Value); 106 }; 107 108 template <> 109 struct ScalarEnumerationTraits<COFF::SymbolBaseType> { 110 static void enumeration(IO &IO, COFF::SymbolBaseType &Value); 111 }; 112 113 template <> 114 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> { 115 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value); 116 }; 117 118 template <> 119 struct ScalarEnumerationTraits<COFF::SymbolComplexType> { 120 static void enumeration(IO &IO, COFF::SymbolComplexType &Value); 121 }; 122 123 template <> 124 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> { 125 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value); 126 }; 127 128 template <> 129 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> { 130 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value); 131 }; 132 133 template <> 134 struct ScalarBitSetTraits<COFF::Characteristics> { 135 static void bitset(IO &IO, COFF::Characteristics &Value); 136 }; 137 138 template <> 139 struct ScalarBitSetTraits<COFF::SectionCharacteristics> { 140 static void bitset(IO &IO, COFF::SectionCharacteristics &Value); 141 }; 142 143 template <> 144 struct MappingTraits<COFFYAML::Relocation> { 145 static void mapping(IO &IO, COFFYAML::Relocation &Rel); 146 }; 147 148 template <> 149 struct MappingTraits<COFF::header> { 150 static void mapping(IO &IO, COFF::header &H); 151 }; 152 153 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> { 154 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD); 155 }; 156 157 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> { 158 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS); 159 }; 160 161 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> { 162 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE); 163 }; 164 165 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> { 166 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD); 167 }; 168 169 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> { 170 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT); 171 }; 172 173 template <> 174 struct MappingTraits<COFFYAML::Symbol> { 175 static void mapping(IO &IO, COFFYAML::Symbol &S); 176 }; 177 178 template <> 179 struct MappingTraits<COFFYAML::Section> { 180 static void mapping(IO &IO, COFFYAML::Section &Sec); 181 }; 182 183 template <> 184 struct MappingTraits<COFFYAML::Object> { 185 static void mapping(IO &IO, COFFYAML::Object &Obj); 186 }; 187 188 } // end namespace yaml 189 } // end namespace llvm 190 191 #endif 192