18eacce707f66174d6802236e93572ab00b84301
[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
40 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
41 // since 64-bit can hold 32-bit values too.
42 struct Header {
43   ELF_ELFCLASS Class;
44   ELF_ELFDATA Data;
45   ELF_ET Type;
46   ELF_EM Machine;
47   llvm::yaml::Hex64 Entry;
48 };
49 struct Object {
50   Header Header;
51 };
52
53 } // end namespace ELFYAML
54 } // end namespace llvm
55
56 namespace llvm {
57 namespace yaml {
58
59 template <>
60 struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
61   static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
62 };
63
64 template <>
65 struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
66   static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
67 };
68
69 template <>
70 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
71   static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
72 };
73
74 template <>
75 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
76   static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
77 };
78
79 template <>
80 struct MappingTraits<ELFYAML::Header> {
81   static void mapping(IO &IO, ELFYAML::Header &Header);
82 };
83
84 template <>
85 struct MappingTraits<ELFYAML::Object> {
86   static void mapping(IO &IO, ELFYAML::Object &Object);
87 };
88
89 } // end namespace yaml
90 } // end namespace llvm
91
92 #endif