Disable each MachineFunctionPass for 'optnone' functions, unless that
[oota-llvm.git] / include / llvm / Object / ELFYAML.h
1 //===- ELFYAML.h - ELF 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 /// \file
11 /// \brief This file declares classes for handling the YAML representation
12 /// of ELF.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_OBJECT_ELFYAML_H
17 #define LLVM_OBJECT_ELFYAML_H
18
19 #include "llvm/Object/YAML.h"
20 #include "llvm/Support/ELF.h"
21
22 namespace llvm {
23 namespace ELFYAML {
24
25 // These types are invariant across 32/64-bit ELF, so for simplicity just
26 // directly give them their exact sizes. We don't need to worry about
27 // endianness because these are just the types in the YAMLIO structures,
28 // and are appropriately converted to the necessary endianness when
29 // reading/generating binary object files.
30 // The naming of these types is intended to be ELF_PREFIX, where PREFIX is
31 // the common prefix of the respective constants. E.g. ELF_EM corresponds
32 // to the `e_machine` constants, like `EM_X86_64`.
33 // In the future, these would probably be better suited by C++11 enum
34 // class's with appropriate fixed underlying type.
35 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)
36 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
37 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
38 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
39 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
40 // Just use 64, since it can hold 32-bit values too.
41 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
42 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
43 // Just use 64, since it can hold 32-bit values too.
44 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
45 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
46
47 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
48 // since 64-bit can hold 32-bit values too.
49 struct FileHeader {
50   ELF_ELFCLASS Class;
51   ELF_ELFDATA Data;
52   ELF_ELFOSABI OSABI;
53   ELF_ET Type;
54   ELF_EM Machine;
55   ELF_EF Flags;
56   llvm::yaml::Hex64 Entry;
57 };
58 struct Symbol {
59   StringRef Name;
60   ELF_STT Type;
61   StringRef Section;
62   llvm::yaml::Hex64 Value;
63   llvm::yaml::Hex64 Size;
64 };
65 struct LocalGlobalWeakSymbols {
66   std::vector<Symbol> Local;
67   std::vector<Symbol> Global;
68   std::vector<Symbol> Weak;
69 };
70 struct Section {
71   StringRef Name;
72   ELF_SHT Type;
73   ELF_SHF Flags;
74   llvm::yaml::Hex64 Address;
75   object::yaml::BinaryRef Content;
76   StringRef Link;
77   llvm::yaml::Hex64 AddressAlign;
78 };
79 struct Object {
80   FileHeader Header;
81   std::vector<Section> Sections;
82   // Although in reality the symbols reside in a section, it is a lot
83   // cleaner and nicer if we read them from the YAML as a separate
84   // top-level key, which automatically ensures that invariants like there
85   // being a single SHT_SYMTAB section are upheld.
86   LocalGlobalWeakSymbols Symbols;
87 };
88
89 } // end namespace ELFYAML
90 } // end namespace llvm
91
92 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Section)
93 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
94
95 namespace llvm {
96 namespace yaml {
97
98 template <>
99 struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
100   static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
101 };
102
103 template <>
104 struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
105   static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
106 };
107
108 template <>
109 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
110   static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
111 };
112
113 template <>
114 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
115   static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
116 };
117
118 template <>
119 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
120   static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
121 };
122
123 template <>
124 struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
125   static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
126 };
127
128 template <>
129 struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
130   static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
131 };
132
133 template <>
134 struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
135   static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
136 };
137
138 template <>
139 struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
140   static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
141 };
142
143 template <>
144 struct MappingTraits<ELFYAML::FileHeader> {
145   static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
146 };
147
148 template <>
149 struct MappingTraits<ELFYAML::Symbol> {
150   static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
151 };
152
153 template <>
154 struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
155   static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
156 };
157
158 template <>
159 struct MappingTraits<ELFYAML::Section> {
160   static void mapping(IO &IO, ELFYAML::Section &Section);
161 };
162
163 template <>
164 struct MappingTraits<ELFYAML::Object> {
165   static void mapping(IO &IO, ELFYAML::Object &Object);
166 };
167
168 } // end namespace yaml
169 } // end namespace llvm
170
171 #endif