ELFYAML.h revision 5918b7a03d4d6a52e18f7c102250c9cfd6ae52dd
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)//===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===// 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// The LLVM Compiler Infrastructure 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// License. See LICENSE.TXT for details. 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//===----------------------------------------------------------------------===// 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// \file 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// \brief This file declares classes for handling the YAML representation 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// of ELF. 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/// 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)//===----------------------------------------------------------------------===// 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef LLVM_OBJECT_ELFYAML_H 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define LLVM_OBJECT_ELFYAML_H 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "llvm/Object/YAML.h" 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "llvm/Support/ELF.h" 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace llvm { 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ELFYAML { 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// These types are invariant across 32/64-bit ELF, so for simplicity just 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// directly give them their exact sizes. We don't need to worry about 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// endianness because these are just the types in the YAMLIO structures, 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// and are appropriately converted to the necessary endianness when 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// reading/generating binary object files. 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// The naming of these types is intended to be ELF_PREFIX, where PREFIX is 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// the common prefix of the respective constants. E.g. ELF_EM corresponds 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// to the `e_machine` constants, like `EM_X86_64`. 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// In the future, these would probably be better suited by C++11 enum 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// class's with appropriate fixed underlying type. 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET); 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM); 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS); 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA); 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// For now, hardcode 64 bits everywhere that 32 or 64 would be needed 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// since 64-bit can hold 32-bit values too. 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct Header { 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ELF_ELFCLASS Class; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ELF_ELFDATA Data; 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ELF_ET Type; 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ELF_EM Machine; 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) llvm::yaml::Hex64 Entry; 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct Object { 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Header Header; 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // end namespace ELFYAML 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // end namespace llvm 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace llvm { 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace yaml { 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ScalarEnumerationTraits<ELFYAML::ELF_ET> { 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void enumeration(IO &IO, ELFYAML::ELF_ET &Value); 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> { 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value); 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> { 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value); 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct MappingTraits<ELFYAML::Header> { 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void mapping(IO &IO, ELFYAML::Header &Header); 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <> 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct MappingTraits<ELFYAML::Object> { 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void mapping(IO &IO, ELFYAML::Object &Object); 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // end namespace yaml 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // end namespace llvm 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)