Convert obj2yaml to use yamlio.
[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
18 #include "llvm/Support/COFF.h"
19 #include "llvm/Support/YAMLTraits.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   struct Section {
40     COFF::section Header;
41     unsigned Alignment;
42     StringRef SectionData;
43     std::vector<COFF::relocation> Relocations;
44     StringRef Name;
45     Section();
46   };
47
48   struct Symbol {
49     COFF::symbol Header;
50     COFF::SymbolBaseType SimpleType;
51     COFF::SymbolComplexType ComplexType;
52     StringRef AuxiliaryData;
53     StringRef Name;
54     Symbol();
55   };
56
57   struct Object {
58     COFF::header Header;
59     std::vector<Section> Sections;
60     std::vector<Symbol> Symbols;
61     Object();
62   };
63 }
64 }
65
66 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
67 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
68 LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
69
70 namespace llvm {
71 namespace yaml {
72
73 template <>
74 struct ScalarEnumerationTraits<COFF::MachineTypes> {
75   static void enumeration(IO &IO, COFF::MachineTypes &Value);
76 };
77
78 template <>
79 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
80   static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
81 };
82
83 template <>
84 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
85   static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
86 };
87
88 template <>
89 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
90   static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
91 };
92
93 template <>
94 struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
95   static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
96 };
97
98 template <>
99 struct ScalarBitSetTraits<COFF::Characteristics> {
100   static void bitset(IO &IO, COFF::Characteristics &Value);
101 };
102
103 template <>
104 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
105   static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
106 };
107
108 template <>
109 struct MappingTraits<COFF::relocation> {
110   static void mapping(IO &IO, COFF::relocation &Rel);
111 };
112
113 template <>
114 struct MappingTraits<COFF::header> {
115   static void mapping(IO &IO, COFF::header &H);
116 };
117
118 template <>
119 struct MappingTraits<COFFYAML::Symbol> {
120   static void mapping(IO &IO, COFFYAML::Symbol &S);
121 };
122
123 template <>
124 struct MappingTraits<COFFYAML::Section> {
125   static void mapping(IO &IO, COFFYAML::Section &Sec);
126 };
127
128 template <>
129 struct MappingTraits<COFFYAML::Object> {
130   static void mapping(IO &IO, COFFYAML::Object &Obj);
131 };
132
133 } // end namespace yaml
134 } // end namespace llvm
135
136 #endif