ELFYAML.h revision 274264ce2ba93d26702f7ebfe6aea121df44113f
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 22namespace llvm { 23namespace 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. 35LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET) 36LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM) 37LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS) 38LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA) 39LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT) 40// Just use 64, since it can hold 32-bit values too. 41LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF) 42 43// For now, hardcode 64 bits everywhere that 32 or 64 would be needed 44// since 64-bit can hold 32-bit values too. 45struct FileHeader { 46 ELF_ELFCLASS Class; 47 ELF_ELFDATA Data; 48 ELF_ET Type; 49 ELF_EM Machine; 50 llvm::yaml::Hex64 Entry; 51}; 52struct Section { 53 StringRef Name; 54 ELF_SHT Type; 55 ELF_SHF Flags; 56}; 57struct Object { 58 FileHeader Header; 59 std::vector<Section> Sections; 60}; 61 62} // end namespace ELFYAML 63} // end namespace llvm 64 65LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Section) 66 67namespace llvm { 68namespace yaml { 69 70template <> 71struct ScalarEnumerationTraits<ELFYAML::ELF_ET> { 72 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value); 73}; 74 75template <> 76struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { 77 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); 78}; 79 80template <> 81struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> { 82 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value); 83}; 84 85template <> 86struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> { 87 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value); 88}; 89 90template <> 91struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> { 92 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value); 93}; 94 95template <> 96struct ScalarBitSetTraits<ELFYAML::ELF_SHF> { 97 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value); 98}; 99 100template <> 101struct MappingTraits<ELFYAML::FileHeader> { 102 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr); 103}; 104 105template <> 106struct MappingTraits<ELFYAML::Section> { 107 static void mapping(IO &IO, ELFYAML::Section &Section); 108}; 109 110template <> 111struct MappingTraits<ELFYAML::Object> { 112 static void mapping(IO &IO, ELFYAML::Object &Object); 113}; 114 115} // end namespace yaml 116} // end namespace llvm 117 118#endif 119