LLVM API Documentation

COFFYAML.h
Go to the documentation of this file.
00001 //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares classes for handling the YAML representation of COFF.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_OBJECT_COFFYAML_H
00015 #define LLVM_OBJECT_COFFYAML_H
00016 
00017 #include "llvm/ADT/Optional.h"
00018 #include "llvm/MC/YAML.h"
00019 #include "llvm/Support/COFF.h"
00020 
00021 namespace llvm {
00022 
00023 namespace COFF {
00024 inline Characteristics operator|(Characteristics a, Characteristics b) {
00025   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
00026   return static_cast<Characteristics>(Ret);
00027 }
00028 
00029 inline SectionCharacteristics operator|(SectionCharacteristics a,
00030                                         SectionCharacteristics b) {
00031   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
00032   return static_cast<SectionCharacteristics>(Ret);
00033 }
00034 }
00035 
00036 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
00037 // to use yaml::IO, we use these structures which are closer to the source.
00038 namespace COFFYAML {
00039   LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
00040   LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
00041   LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
00042 
00043   struct Relocation {
00044     uint32_t VirtualAddress;
00045     uint16_t Type;
00046     StringRef SymbolName;
00047   };
00048 
00049   struct Section {
00050     COFF::section Header;
00051     unsigned Alignment;
00052     yaml::BinaryRef SectionData;
00053     std::vector<Relocation> Relocations;
00054     StringRef Name;
00055     Section();
00056   };
00057 
00058   struct Symbol {
00059     COFF::symbol Header;
00060     COFF::SymbolBaseType SimpleType;
00061     COFF::SymbolComplexType ComplexType;
00062     Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
00063     Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
00064     Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
00065     StringRef File;
00066     Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
00067     Optional<COFF::AuxiliaryCLRToken> CLRToken;
00068     StringRef Name;
00069     Symbol();
00070   };
00071 
00072   struct Object {
00073     COFF::header Header;
00074     std::vector<Section> Sections;
00075     std::vector<Symbol> Symbols;
00076     Object();
00077   };
00078 }
00079 }
00080 
00081 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
00082 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
00083 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
00084 
00085 namespace llvm {
00086 namespace yaml {
00087 
00088 template <>
00089 struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
00090   static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
00091 };
00092 
00093 template <>
00094 struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
00095   static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
00096 };
00097 
00098 template <>
00099 struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
00100   static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
00101 };
00102 
00103 template <>
00104 struct ScalarEnumerationTraits<COFF::MachineTypes> {
00105   static void enumeration(IO &IO, COFF::MachineTypes &Value);
00106 };
00107 
00108 template <>
00109 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
00110   static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
00111 };
00112 
00113 template <>
00114 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
00115   static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
00116 };
00117 
00118 template <>
00119 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
00120   static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
00121 };
00122 
00123 template <>
00124 struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
00125   static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
00126 };
00127 
00128 template <>
00129 struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
00130   static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
00131 };
00132 
00133 template <>
00134 struct ScalarBitSetTraits<COFF::Characteristics> {
00135   static void bitset(IO &IO, COFF::Characteristics &Value);
00136 };
00137 
00138 template <>
00139 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
00140   static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
00141 };
00142 
00143 template <>
00144 struct MappingTraits<COFFYAML::Relocation> {
00145   static void mapping(IO &IO, COFFYAML::Relocation &Rel);
00146 };
00147 
00148 template <>
00149 struct MappingTraits<COFF::header> {
00150   static void mapping(IO &IO, COFF::header &H);
00151 };
00152 
00153 template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
00154   static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
00155 };
00156 
00157 template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
00158   static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
00159 };
00160 
00161 template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
00162   static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
00163 };
00164 
00165 template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
00166   static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
00167 };
00168 
00169 template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
00170   static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
00171 };
00172 
00173 template <>
00174 struct MappingTraits<COFFYAML::Symbol> {
00175   static void mapping(IO &IO, COFFYAML::Symbol &S);
00176 };
00177 
00178 template <>
00179 struct MappingTraits<COFFYAML::Section> {
00180   static void mapping(IO &IO, COFFYAML::Section &Sec);
00181 };
00182 
00183 template <>
00184 struct MappingTraits<COFFYAML::Object> {
00185   static void mapping(IO &IO, COFFYAML::Object &Obj);
00186 };
00187 
00188 } // end namespace yaml
00189 } // end namespace llvm
00190 
00191 #endif