LCOV - code coverage report
Current view: top level - include/llvm/ObjectYAML - COFFYAML.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 9 12 75.0 %
Date: 2017-09-14 15:23:50 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- COFFYAML.h - COFF 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             : // This file declares classes for handling the YAML representation of COFF.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_OBJECTYAML_COFFYAML_H
      15             : #define LLVM_OBJECTYAML_COFFYAML_H
      16             : 
      17             : #include "llvm/ADT/Optional.h"
      18             : #include "llvm/ADT/StringRef.h"
      19             : #include "llvm/BinaryFormat/COFF.h"
      20             : #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
      21             : #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
      22             : #include "llvm/ObjectYAML/YAML.h"
      23             : #include <cstdint>
      24             : #include <vector>
      25             : 
      26             : namespace llvm {
      27             : 
      28             : namespace COFF {
      29             : 
      30             : inline Characteristics operator|(Characteristics a, Characteristics b) {
      31          24 :   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
      32             :   return static_cast<Characteristics>(Ret);
      33             : }
      34             : 
      35             : inline SectionCharacteristics operator|(SectionCharacteristics a,
      36             :                                         SectionCharacteristics b) {
      37        1108 :   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
      38             :   return static_cast<SectionCharacteristics>(Ret);
      39             : }
      40             : 
      41             : inline DLLCharacteristics operator|(DLLCharacteristics a,
      42             :                                     DLLCharacteristics b) {
      43           0 :   uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
      44           0 :   return static_cast<DLLCharacteristics>(Ret);
      45             : }
      46             : 
      47             : } // end namespace COFF
      48             : 
      49             : // The structure of the yaml files is not an exact 1:1 match to COFF. In order
      50             : // to use yaml::IO, we use these structures which are closer to the source.
      51             : namespace COFFYAML {
      52             : 
      53         860 : LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
      54          15 : LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
      55           0 : LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
      56             : 
      57         445 : struct Relocation {
      58             :   uint32_t VirtualAddress;
      59             :   uint16_t Type;
      60             :   StringRef SymbolName;
      61             : };
      62             : 
      63        2561 : struct Section {
      64             :   COFF::section Header;
      65             :   unsigned Alignment = 0;
      66             :   yaml::BinaryRef SectionData;
      67             :   std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
      68             :   std::vector<CodeViewYAML::LeafRecord> DebugT;
      69             :   std::vector<Relocation> Relocations;
      70             :   StringRef Name;
      71             : 
      72             :   Section();
      73             : };
      74             : 
      75        6024 : struct Symbol {
      76             :   COFF::symbol Header;
      77             :   COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL;
      78             :   COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL;
      79             :   Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
      80             :   Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
      81             :   Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
      82             :   StringRef File;
      83             :   Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
      84             :   Optional<COFF::AuxiliaryCLRToken> CLRToken;
      85             :   StringRef Name;
      86             : 
      87             :   Symbol();
      88             : };
      89             : 
      90        8064 : struct PEHeader {
      91             :   COFF::PE32Header Header;
      92             :   Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
      93             : };
      94             : 
      95         528 : struct Object {
      96             :   Optional<PEHeader> OptionalHeader;
      97             :   COFF::header Header;
      98             :   std::vector<Section> Sections;
      99             :   std::vector<Symbol> Symbols;
     100             : 
     101             :   Object();
     102             : };
     103             : 
     104             : } // end namespace COFFYAML
     105             : 
     106             : } // end namespace llvm
     107             : 
     108             : LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
     109             : LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
     110             : LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
     111             : 
     112             : namespace llvm {
     113             : namespace yaml {
     114             : 
     115             : template <>
     116             : struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
     117             :   static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
     118             : };
     119             : 
     120             : template <>
     121             : struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
     122             :   static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
     123             : };
     124             : 
     125             : template <>
     126             : struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
     127             :   static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
     128             : };
     129             : 
     130             : template <>
     131             : struct ScalarEnumerationTraits<COFF::MachineTypes> {
     132             :   static void enumeration(IO &IO, COFF::MachineTypes &Value);
     133             : };
     134             : 
     135             : template <>
     136             : struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
     137             :   static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
     138             : };
     139             : 
     140             : template <>
     141             : struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
     142             :   static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
     143             : };
     144             : 
     145             : template <>
     146             : struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
     147             :   static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
     148             : };
     149             : 
     150             : template <>
     151             : struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
     152             :   static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
     153             : };
     154             : 
     155             : template <>
     156             : struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
     157             :   static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
     158             : };
     159             : 
     160             : template <>
     161             : struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
     162             :   static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
     163             : };
     164             : 
     165             : template <>
     166             : struct ScalarBitSetTraits<COFF::Characteristics> {
     167             :   static void bitset(IO &IO, COFF::Characteristics &Value);
     168             : };
     169             : 
     170             : template <>
     171             : struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
     172             :   static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
     173             : };
     174             : 
     175             : template <>
     176             : struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
     177             :   static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
     178             : };
     179             : 
     180             : template <>
     181             : struct MappingTraits<COFFYAML::Relocation> {
     182             :   static void mapping(IO &IO, COFFYAML::Relocation &Rel);
     183             : };
     184             : 
     185             : template <>
     186             : struct MappingTraits<COFFYAML::PEHeader> {
     187             :   static void mapping(IO &IO, COFFYAML::PEHeader &PH);
     188             : };
     189             : 
     190             : template <>
     191             : struct MappingTraits<COFF::DataDirectory> {
     192             :   static void mapping(IO &IO, COFF::DataDirectory &DD);
     193             : };
     194             : 
     195             : template <>
     196             : struct MappingTraits<COFF::header> {
     197             :   static void mapping(IO &IO, COFF::header &H);
     198             : };
     199             : 
     200             : template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
     201             :   static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
     202             : };
     203             : 
     204             : template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
     205             :   static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
     206             : };
     207             : 
     208             : template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
     209             :   static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
     210             : };
     211             : 
     212             : template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
     213             :   static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
     214             : };
     215             : 
     216             : template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
     217             :   static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
     218             : };
     219             : 
     220             : template <>
     221             : struct MappingTraits<COFFYAML::Symbol> {
     222             :   static void mapping(IO &IO, COFFYAML::Symbol &S);
     223             : };
     224             : 
     225             : template <>
     226             : struct MappingTraits<COFFYAML::Section> {
     227             :   static void mapping(IO &IO, COFFYAML::Section &Sec);
     228             : };
     229             : 
     230             : template <>
     231             : struct MappingTraits<COFFYAML::Object> {
     232             :   static void mapping(IO &IO, COFFYAML::Object &Obj);
     233             : };
     234             : 
     235             : } // end namespace yaml
     236             : } // end namespace llvm
     237             : 
     238             : #endif // LLVM_OBJECTYAML_COFFYAML_H

Generated by: LCOV version 1.13