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

Generated by: LCOV version 1.13