LLVM  8.0.1
COFFYAML.h
Go to the documentation of this file.
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_OBJECTYAML_COFFYAML_H
15 #define LLVM_OBJECTYAML_COFFYAML_H
16 
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/COFF.h"
23 #include "llvm/ObjectYAML/YAML.h"
24 #include <cstdint>
25 #include <vector>
26 
27 namespace llvm {
28 
29 namespace COFF {
30 
32  uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
33  return static_cast<Characteristics>(Ret);
34 }
35 
38  uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
39  return static_cast<SectionCharacteristics>(Ret);
40 }
41 
44  uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
45  return static_cast<DLLCharacteristics>(Ret);
46 }
47 
48 } // end namespace COFF
49 
50 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
51 // to use yaml::IO, we use these structures which are closer to the source.
52 namespace COFFYAML {
53 
54 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
55 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
56 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
57 
58 struct Relocation {
60  uint16_t Type;
61 
62  // Normally a Relocation can refer to the symbol via its name.
63  // It can also use a direct symbol table index instead (with no name
64  // specified), allowing disambiguating between multiple symbols with the
65  // same name or crafting intentionally broken files for testing.
68 };
69 
70 struct Section {
72  unsigned Alignment = 0;
74  std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
75  std::vector<CodeViewYAML::LeafRecord> DebugT;
76  std::vector<CodeViewYAML::LeafRecord> DebugP;
78  std::vector<Relocation> Relocations;
80 
81  Section();
82 };
83 
84 struct Symbol {
95 
96  Symbol();
97 };
98 
99 struct PEHeader {
102 };
103 
104 struct Object {
107  std::vector<Section> Sections;
108  std::vector<Symbol> Symbols;
109 
110  Object();
111 };
112 
113 } // end namespace COFFYAML
114 
115 } // end namespace llvm
116 
117 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
118 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
119 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
120 
121 namespace llvm {
122 namespace yaml {
123 
124 template <>
125 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
126  static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
127 };
128 
129 template <>
130 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
131  static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
132 };
133 
134 template <>
135 struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
136  static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
137 };
138 
139 template <>
140 struct ScalarEnumerationTraits<COFF::MachineTypes> {
141  static void enumeration(IO &IO, COFF::MachineTypes &Value);
142 };
143 
144 template <>
145 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
146  static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
147 };
148 
149 template <>
150 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
151  static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
152 };
153 
154 template <>
155 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
156  static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
157 };
158 
159 template <>
160 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
161  static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
162 };
163 
164 template <>
165 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
166  static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
167 };
168 
169 template <>
170 struct ScalarEnumerationTraits<COFF::RelocationTypesARM> {
171  static void enumeration(IO &IO, COFF::RelocationTypesARM &Value);
172 };
173 
174 template <>
175 struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> {
176  static void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value);
177 };
178 
179 template <>
180 struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
181  static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
182 };
183 
184 template <>
185 struct ScalarBitSetTraits<COFF::Characteristics> {
186  static void bitset(IO &IO, COFF::Characteristics &Value);
187 };
188 
189 template <>
190 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
191  static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
192 };
193 
194 template <>
195 struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
196  static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
197 };
198 
199 template <>
200 struct MappingTraits<COFFYAML::Relocation> {
201  static void mapping(IO &IO, COFFYAML::Relocation &Rel);
202 };
203 
204 template <>
205 struct MappingTraits<COFFYAML::PEHeader> {
206  static void mapping(IO &IO, COFFYAML::PEHeader &PH);
207 };
208 
209 template <>
210 struct MappingTraits<COFF::DataDirectory> {
211  static void mapping(IO &IO, COFF::DataDirectory &DD);
212 };
213 
214 template <>
215 struct MappingTraits<COFF::header> {
216  static void mapping(IO &IO, COFF::header &H);
217 };
218 
219 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
220  static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
221 };
222 
223 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
224  static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
225 };
226 
227 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
228  static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
229 };
230 
231 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
232  static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
233 };
234 
235 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
236  static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
237 };
238 
239 template <>
240 struct MappingTraits<COFFYAML::Symbol> {
241  static void mapping(IO &IO, COFFYAML::Symbol &S);
242 };
243 
244 template <>
245 struct MappingTraits<COFFYAML::Section> {
246  static void mapping(IO &IO, COFFYAML::Section &Sec);
247 };
248 
249 template <>
250 struct MappingTraits<COFFYAML::Object> {
251  static void mapping(IO &IO, COFFYAML::Object &Obj);
252 };
253 
254 } // end namespace yaml
255 } // end namespace llvm
256 
257 #endif // LLVM_OBJECTYAML_COFFYAML_H
COFF::section Header
Definition: COFFYAML.h:71
SymbolBaseType
Definition: COFF.h:240
COFF::PE32Header Header
Definition: COFFYAML.h:100
WeakExternalCharacteristics
Definition: COFF.h:436
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition: COFFYAML.h:89
RelocationTypeI386
Definition: COFF.h:331
COFF::symbol Header
Definition: COFFYAML.h:85
AuxSymbolType
Definition: COFF.h:269
No complex type; simple scalar variable.
Definition: COFF.h:260
WindowsSubsystem
Definition: COFF.h:598
Characteristics operator|(Characteristics a, Characteristics b)
Definition: COFFYAML.h:31
COFF::header Header
Definition: COFFYAML.h:106
MachineTypes
Definition: COFF.h:94
std::vector< Relocation > Relocations
Definition: COFFYAML.h:78
DLLCharacteristics
Definition: COFF.h:617
RelocationTypesARM64
Definition: COFF.h:383
std::vector< Section > Sections
Definition: COFFYAML.h:107
SectionCharacteristics
Definition: COFF.h:284
RelocationTypeAMD64
Definition: COFF.h:345
std::vector< CodeViewYAML::LeafRecord > DebugP
Definition: COFFYAML.h:76
#define H(x, y, z)
Definition: MD5.cpp:57
No type information or unknown base type.
Definition: COFF.h:241
Characteristics
Definition: COFF.h:124
yaml::BinaryRef SectionData
Definition: COFFYAML.h:73
Optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition: COFFYAML.h:88
std::vector< CodeViewYAML::LeafRecord > DebugT
Definition: COFFYAML.h:75
Optional< COFF::AuxiliaryCLRToken > CLRToken
Definition: COFFYAML.h:93
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: COFF.h:204
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:64
Optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition: COFFYAML.h:90
RelocationTypesARM
Definition: COFF.h:365
COMDATType
Definition: COFF.h:403
std::vector< CodeViewYAML::YAMLDebugSubsection > DebugS
Definition: COFFYAML.h:74
Optional< uint32_t > SymbolTableIndex
Definition: COFFYAML.h:67
LLVM Value Representation.
Definition: Value.h:73
std::vector< Symbol > Symbols
Definition: COFFYAML.h:108
SymbolComplexType
Definition: COFF.h:259
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Optional< CodeViewYAML::DebugHSection > DebugH
Definition: COFFYAML.h:77
Optional< PEHeader > OptionalHeader
Definition: COFFYAML.h:105
Optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition: COFFYAML.h:92