Move BinaryRef to a new include/llvm/Object/YAML.h file.
[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/Object/YAML.h"
18 #include "llvm/Support/COFF.h"
19
20 namespace llvm {
21
22 namespace COFF {
23 inline Characteristics operator|(Characteristics a, Characteristics b) {
24   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
25   return static_cast<Characteristics>(Ret);
26 }
27
28 inline SectionCharacteristics operator|(SectionCharacteristics a,
29                                         SectionCharacteristics b) {
30   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
31   return static_cast<SectionCharacteristics>(Ret);
32 }
33 }
34
35 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
36 // to use yaml::IO, we use these structures which are closer to the source.
37 namespace COFFYAML {
38   struct Section {
39     COFF::section Header;
40     unsigned Alignment;
41     object::yaml::BinaryRef SectionData;
42     std::vector<COFF::relocation> Relocations;
43     StringRef Name;
44     Section();
45   };
46
47   struct Symbol {
48     COFF::symbol Header;
49     COFF::SymbolBaseType SimpleType;
50     COFF::SymbolComplexType ComplexType;
51     object::yaml::BinaryRef AuxiliaryData;
52     StringRef Name;
53     Symbol();
54   };
55
56   struct Object {
57     COFF::header Header;
58     std::vector<Section> Sections;
59     std::vector<Symbol> Symbols;
60     Object();
61   };
62 }
63 }
64
65 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
66 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
67 LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
68
69 namespace llvm {
70 namespace yaml {
71
72 template <>
73 struct ScalarEnumerationTraits<COFF::MachineTypes> {
74   static void enumeration(IO &IO, COFF::MachineTypes &Value);
75 };
76
77 template <>
78 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
79   static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
80 };
81
82 template <>
83 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
84   static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
85 };
86
87 template <>
88 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
89   static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
90 };
91
92 template <>
93 struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
94   static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
95 };
96
97 template <>
98 struct ScalarBitSetTraits<COFF::Characteristics> {
99   static void bitset(IO &IO, COFF::Characteristics &Value);
100 };
101
102 template <>
103 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
104   static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
105 };
106
107 template <>
108 struct MappingTraits<COFF::relocation> {
109   static void mapping(IO &IO, COFF::relocation &Rel);
110 };
111
112 template <>
113 struct MappingTraits<COFF::header> {
114   static void mapping(IO &IO, COFF::header &H);
115 };
116
117 template <>
118 struct MappingTraits<COFFYAML::Symbol> {
119   static void mapping(IO &IO, COFFYAML::Symbol &S);
120 };
121
122 template <>
123 struct MappingTraits<COFFYAML::Section> {
124   static void mapping(IO &IO, COFFYAML::Section &Sec);
125 };
126
127 template <>
128 struct MappingTraits<COFFYAML::Object> {
129   static void mapping(IO &IO, COFFYAML::Object &Obj);
130 };
131
132 } // end namespace yaml
133 } // end namespace llvm
134
135 #endif