Object: Provide a richer means of describing auxiliary symbols
[oota-llvm.git] / include / llvm / Object / COFFYAML.h
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/Object/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     object::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::RelocationTypeX86> {
125   static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
126 };
127
128 template <>
129 struct ScalarBitSetTraits<COFF::Characteristics> {
130   static void bitset(IO &IO, COFF::Characteristics &Value);
131 };
132
133 template <>
134 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
135   static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
136 };
137
138 template <>
139 struct MappingTraits<COFFYAML::Relocation> {
140   static void mapping(IO &IO, COFFYAML::Relocation &Rel);
141 };
142
143 template <>
144 struct MappingTraits<COFF::header> {
145   static void mapping(IO &IO, COFF::header &H);
146 };
147
148 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
149   static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
150 };
151
152 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
153   static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
154 };
155
156 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
157   static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
158 };
159
160 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
161   static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
162 };
163
164 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
165   static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
166 };
167
168 template <>
169 struct MappingTraits<COFFYAML::Symbol> {
170   static void mapping(IO &IO, COFFYAML::Symbol &S);
171 };
172
173 template <>
174 struct MappingTraits<COFFYAML::Section> {
175   static void mapping(IO &IO, COFFYAML::Section &Sec);
176 };
177
178 template <>
179 struct MappingTraits<COFFYAML::Object> {
180   static void mapping(IO &IO, COFFYAML::Object &Obj);
181 };
182
183 } // end namespace yaml
184 } // end namespace llvm
185
186 #endif