LCOV - code coverage report
Current view: top level - lib/ObjectYAML - COFFYAML.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 364 390 93.3 %
Date: 2018-07-13 00:08:38 Functions: 25 30 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
       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 defines classes for handling the YAML representation of COFF.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/ObjectYAML/COFFYAML.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include "llvm/Support/YAMLTraits.h"
      17             : #include <cstdint>
      18             : #include <cstring>
      19             : 
      20             : #define ECase(X) IO.enumCase(Value, #X, COFF::X);
      21             : 
      22             : namespace llvm {
      23             : 
      24             : namespace COFFYAML {
      25             : 
      26        1144 : Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
      27        2318 : Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
      28         440 : Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
      29             : 
      30             : } // end namespace COFFYAML
      31             : 
      32             : namespace yaml {
      33             : 
      34          92 : void ScalarEnumerationTraits<COFFYAML::COMDATType>::enumeration(
      35             :     IO &IO, COFFYAML::COMDATType &Value) {
      36          92 :   IO.enumCase(Value, "0", 0);
      37          92 :   ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
      38          92 :   ECase(IMAGE_COMDAT_SELECT_ANY);
      39          92 :   ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
      40          92 :   ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
      41          92 :   ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
      42          92 :   ECase(IMAGE_COMDAT_SELECT_LARGEST);
      43          92 :   ECase(IMAGE_COMDAT_SELECT_NEWEST);
      44          92 : }
      45             : 
      46             : void
      47           6 : ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics>::enumeration(
      48             :     IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
      49           6 :   IO.enumCase(Value, "0", 0);
      50           6 :   ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
      51           6 :   ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
      52           6 :   ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
      53           6 : }
      54             : 
      55           0 : void ScalarEnumerationTraits<COFFYAML::AuxSymbolType>::enumeration(
      56             :     IO &IO, COFFYAML::AuxSymbolType &Value) {
      57           0 :   ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
      58           0 : }
      59             : 
      60         220 : void ScalarEnumerationTraits<COFF::MachineTypes>::enumeration(
      61             :     IO &IO, COFF::MachineTypes &Value) {
      62         220 :   ECase(IMAGE_FILE_MACHINE_UNKNOWN);
      63         220 :   ECase(IMAGE_FILE_MACHINE_AM33);
      64         220 :   ECase(IMAGE_FILE_MACHINE_AMD64);
      65         220 :   ECase(IMAGE_FILE_MACHINE_ARM);
      66         220 :   ECase(IMAGE_FILE_MACHINE_ARMNT);
      67         220 :   ECase(IMAGE_FILE_MACHINE_ARM64);
      68         220 :   ECase(IMAGE_FILE_MACHINE_EBC);
      69         220 :   ECase(IMAGE_FILE_MACHINE_I386);
      70         220 :   ECase(IMAGE_FILE_MACHINE_IA64);
      71         220 :   ECase(IMAGE_FILE_MACHINE_M32R);
      72         220 :   ECase(IMAGE_FILE_MACHINE_MIPS16);
      73         220 :   ECase(IMAGE_FILE_MACHINE_MIPSFPU);
      74         220 :   ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
      75         220 :   ECase(IMAGE_FILE_MACHINE_POWERPC);
      76         220 :   ECase(IMAGE_FILE_MACHINE_POWERPCFP);
      77         220 :   ECase(IMAGE_FILE_MACHINE_R4000);
      78         220 :   ECase(IMAGE_FILE_MACHINE_SH3);
      79         220 :   ECase(IMAGE_FILE_MACHINE_SH3DSP);
      80         220 :   ECase(IMAGE_FILE_MACHINE_SH4);
      81         220 :   ECase(IMAGE_FILE_MACHINE_SH5);
      82         220 :   ECase(IMAGE_FILE_MACHINE_THUMB);
      83         220 :   ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
      84         220 : }
      85             : 
      86        1159 : void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
      87             :     IO &IO, COFF::SymbolBaseType &Value) {
      88        1159 :   ECase(IMAGE_SYM_TYPE_NULL);
      89        1159 :   ECase(IMAGE_SYM_TYPE_VOID);
      90        1159 :   ECase(IMAGE_SYM_TYPE_CHAR);
      91        1159 :   ECase(IMAGE_SYM_TYPE_SHORT);
      92        1159 :   ECase(IMAGE_SYM_TYPE_INT);
      93        1159 :   ECase(IMAGE_SYM_TYPE_LONG);
      94        1159 :   ECase(IMAGE_SYM_TYPE_FLOAT);
      95        1159 :   ECase(IMAGE_SYM_TYPE_DOUBLE);
      96        1159 :   ECase(IMAGE_SYM_TYPE_STRUCT);
      97        1159 :   ECase(IMAGE_SYM_TYPE_UNION);
      98        1159 :   ECase(IMAGE_SYM_TYPE_ENUM);
      99        1159 :   ECase(IMAGE_SYM_TYPE_MOE);
     100        1159 :   ECase(IMAGE_SYM_TYPE_BYTE);
     101        1159 :   ECase(IMAGE_SYM_TYPE_WORD);
     102        1159 :   ECase(IMAGE_SYM_TYPE_UINT);
     103        1159 :   ECase(IMAGE_SYM_TYPE_DWORD);
     104        1159 : }
     105             : 
     106        1159 : void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
     107             :     IO &IO, COFF::SymbolStorageClass &Value) {
     108        1159 :   ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
     109        1159 :   ECase(IMAGE_SYM_CLASS_NULL);
     110        1159 :   ECase(IMAGE_SYM_CLASS_AUTOMATIC);
     111        1159 :   ECase(IMAGE_SYM_CLASS_EXTERNAL);
     112        1159 :   ECase(IMAGE_SYM_CLASS_STATIC);
     113        1159 :   ECase(IMAGE_SYM_CLASS_REGISTER);
     114        1159 :   ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
     115        1159 :   ECase(IMAGE_SYM_CLASS_LABEL);
     116        1159 :   ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
     117        1159 :   ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
     118        1159 :   ECase(IMAGE_SYM_CLASS_ARGUMENT);
     119        1159 :   ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
     120        1159 :   ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
     121        1159 :   ECase(IMAGE_SYM_CLASS_UNION_TAG);
     122        1159 :   ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
     123        1159 :   ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
     124        1159 :   ECase(IMAGE_SYM_CLASS_ENUM_TAG);
     125        1159 :   ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
     126        1159 :   ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
     127        1159 :   ECase(IMAGE_SYM_CLASS_BIT_FIELD);
     128        1159 :   ECase(IMAGE_SYM_CLASS_BLOCK);
     129        1159 :   ECase(IMAGE_SYM_CLASS_FUNCTION);
     130        1159 :   ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
     131        1159 :   ECase(IMAGE_SYM_CLASS_FILE);
     132        1159 :   ECase(IMAGE_SYM_CLASS_SECTION);
     133        1159 :   ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
     134        1159 :   ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
     135        1159 : }
     136             : 
     137        1159 : void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
     138             :     IO &IO, COFF::SymbolComplexType &Value) {
     139        1159 :   ECase(IMAGE_SYM_DTYPE_NULL);
     140        1159 :   ECase(IMAGE_SYM_DTYPE_POINTER);
     141        1159 :   ECase(IMAGE_SYM_DTYPE_FUNCTION);
     142        1159 :   ECase(IMAGE_SYM_DTYPE_ARRAY);
     143        1159 : }
     144             : 
     145         182 : void ScalarEnumerationTraits<COFF::RelocationTypeI386>::enumeration(
     146             :     IO &IO, COFF::RelocationTypeI386 &Value) {
     147         182 :   ECase(IMAGE_REL_I386_ABSOLUTE);
     148         182 :   ECase(IMAGE_REL_I386_DIR16);
     149         182 :   ECase(IMAGE_REL_I386_REL16);
     150         182 :   ECase(IMAGE_REL_I386_DIR32);
     151         182 :   ECase(IMAGE_REL_I386_DIR32NB);
     152         182 :   ECase(IMAGE_REL_I386_SEG12);
     153         182 :   ECase(IMAGE_REL_I386_SECTION);
     154         182 :   ECase(IMAGE_REL_I386_SECREL);
     155         182 :   ECase(IMAGE_REL_I386_TOKEN);
     156         182 :   ECase(IMAGE_REL_I386_SECREL7);
     157         182 :   ECase(IMAGE_REL_I386_REL32);
     158         182 : }
     159             : 
     160         432 : void ScalarEnumerationTraits<COFF::RelocationTypeAMD64>::enumeration(
     161             :     IO &IO, COFF::RelocationTypeAMD64 &Value) {
     162         432 :   ECase(IMAGE_REL_AMD64_ABSOLUTE);
     163         432 :   ECase(IMAGE_REL_AMD64_ADDR64);
     164         432 :   ECase(IMAGE_REL_AMD64_ADDR32);
     165         432 :   ECase(IMAGE_REL_AMD64_ADDR32NB);
     166         432 :   ECase(IMAGE_REL_AMD64_REL32);
     167         432 :   ECase(IMAGE_REL_AMD64_REL32_1);
     168         432 :   ECase(IMAGE_REL_AMD64_REL32_2);
     169         432 :   ECase(IMAGE_REL_AMD64_REL32_3);
     170         432 :   ECase(IMAGE_REL_AMD64_REL32_4);
     171         432 :   ECase(IMAGE_REL_AMD64_REL32_5);
     172         432 :   ECase(IMAGE_REL_AMD64_SECTION);
     173         432 :   ECase(IMAGE_REL_AMD64_SECREL);
     174         432 :   ECase(IMAGE_REL_AMD64_SECREL7);
     175         432 :   ECase(IMAGE_REL_AMD64_TOKEN);
     176         432 :   ECase(IMAGE_REL_AMD64_SREL32);
     177         432 :   ECase(IMAGE_REL_AMD64_PAIR);
     178         432 :   ECase(IMAGE_REL_AMD64_SSPAN32);
     179         432 : }
     180             : 
     181          15 : void ScalarEnumerationTraits<COFF::RelocationTypesARM>::enumeration(
     182             :     IO &IO, COFF::RelocationTypesARM &Value) {
     183          15 :   ECase(IMAGE_REL_ARM_ABSOLUTE);
     184          15 :   ECase(IMAGE_REL_ARM_ADDR32);
     185          15 :   ECase(IMAGE_REL_ARM_ADDR32NB);
     186          15 :   ECase(IMAGE_REL_ARM_BRANCH24);
     187          15 :   ECase(IMAGE_REL_ARM_BRANCH11);
     188          15 :   ECase(IMAGE_REL_ARM_TOKEN);
     189          15 :   ECase(IMAGE_REL_ARM_BLX24);
     190          15 :   ECase(IMAGE_REL_ARM_BLX11);
     191          15 :   ECase(IMAGE_REL_ARM_SECTION);
     192          15 :   ECase(IMAGE_REL_ARM_SECREL);
     193          15 :   ECase(IMAGE_REL_ARM_MOV32A);
     194          15 :   ECase(IMAGE_REL_ARM_MOV32T);
     195          15 :   ECase(IMAGE_REL_ARM_BRANCH20T);
     196          15 :   ECase(IMAGE_REL_ARM_BRANCH24T);
     197          15 :   ECase(IMAGE_REL_ARM_BLX23T);
     198          15 : }
     199             : 
     200          45 : void ScalarEnumerationTraits<COFF::RelocationTypesARM64>::enumeration(
     201             :     IO &IO, COFF::RelocationTypesARM64 &Value) {
     202          45 :   ECase(IMAGE_REL_ARM64_ABSOLUTE);
     203          45 :   ECase(IMAGE_REL_ARM64_ADDR32);
     204          45 :   ECase(IMAGE_REL_ARM64_ADDR32NB);
     205          45 :   ECase(IMAGE_REL_ARM64_BRANCH26);
     206          45 :   ECase(IMAGE_REL_ARM64_PAGEBASE_REL21);
     207          45 :   ECase(IMAGE_REL_ARM64_REL21);
     208          45 :   ECase(IMAGE_REL_ARM64_PAGEOFFSET_12A);
     209          45 :   ECase(IMAGE_REL_ARM64_PAGEOFFSET_12L);
     210          45 :   ECase(IMAGE_REL_ARM64_SECREL);
     211          45 :   ECase(IMAGE_REL_ARM64_SECREL_LOW12A);
     212          45 :   ECase(IMAGE_REL_ARM64_SECREL_HIGH12A);
     213          45 :   ECase(IMAGE_REL_ARM64_SECREL_LOW12L);
     214          45 :   ECase(IMAGE_REL_ARM64_TOKEN);
     215          45 :   ECase(IMAGE_REL_ARM64_SECTION);
     216          45 :   ECase(IMAGE_REL_ARM64_ADDR64);
     217          45 :   ECase(IMAGE_REL_ARM64_BRANCH19);
     218          45 :   ECase(IMAGE_REL_ARM64_BRANCH14);
     219          45 : }
     220             : 
     221           1 : void ScalarEnumerationTraits<COFF::WindowsSubsystem>::enumeration(
     222             :     IO &IO, COFF::WindowsSubsystem &Value) {
     223           1 :   ECase(IMAGE_SUBSYSTEM_UNKNOWN);
     224           1 :   ECase(IMAGE_SUBSYSTEM_NATIVE);
     225           1 :   ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
     226           1 :   ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
     227           1 :   ECase(IMAGE_SUBSYSTEM_OS2_CUI);
     228           1 :   ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
     229           1 :   ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
     230           1 :   ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
     231           1 :   ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
     232           1 :   ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
     233           1 :   ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
     234           1 :   ECase(IMAGE_SUBSYSTEM_EFI_ROM);
     235           1 :   ECase(IMAGE_SUBSYSTEM_XBOX);
     236           1 :   ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
     237           1 : }
     238             : #undef ECase
     239             : 
     240             : #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
     241         218 : void ScalarBitSetTraits<COFF::Characteristics>::bitset(
     242             :     IO &IO, COFF::Characteristics &Value) {
     243         218 :   BCase(IMAGE_FILE_RELOCS_STRIPPED);
     244         218 :   BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
     245         218 :   BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
     246         218 :   BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
     247         218 :   BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
     248         218 :   BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
     249         218 :   BCase(IMAGE_FILE_BYTES_REVERSED_LO);
     250         218 :   BCase(IMAGE_FILE_32BIT_MACHINE);
     251         218 :   BCase(IMAGE_FILE_DEBUG_STRIPPED);
     252         218 :   BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
     253         218 :   BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
     254         218 :   BCase(IMAGE_FILE_SYSTEM);
     255         218 :   BCase(IMAGE_FILE_DLL);
     256         218 :   BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
     257         218 :   BCase(IMAGE_FILE_BYTES_REVERSED_HI);
     258         218 : }
     259             : 
     260         572 : void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
     261             :     IO &IO, COFF::SectionCharacteristics &Value) {
     262         572 :   BCase(IMAGE_SCN_TYPE_NOLOAD);
     263         572 :   BCase(IMAGE_SCN_TYPE_NO_PAD);
     264         572 :   BCase(IMAGE_SCN_CNT_CODE);
     265         572 :   BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
     266         572 :   BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
     267         572 :   BCase(IMAGE_SCN_LNK_OTHER);
     268         572 :   BCase(IMAGE_SCN_LNK_INFO);
     269         572 :   BCase(IMAGE_SCN_LNK_REMOVE);
     270         572 :   BCase(IMAGE_SCN_LNK_COMDAT);
     271         572 :   BCase(IMAGE_SCN_GPREL);
     272         572 :   BCase(IMAGE_SCN_MEM_PURGEABLE);
     273         572 :   BCase(IMAGE_SCN_MEM_16BIT);
     274         572 :   BCase(IMAGE_SCN_MEM_LOCKED);
     275         572 :   BCase(IMAGE_SCN_MEM_PRELOAD);
     276         572 :   BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
     277         572 :   BCase(IMAGE_SCN_MEM_DISCARDABLE);
     278         572 :   BCase(IMAGE_SCN_MEM_NOT_CACHED);
     279         572 :   BCase(IMAGE_SCN_MEM_NOT_PAGED);
     280         572 :   BCase(IMAGE_SCN_MEM_SHARED);
     281         572 :   BCase(IMAGE_SCN_MEM_EXECUTE);
     282         572 :   BCase(IMAGE_SCN_MEM_READ);
     283         572 :   BCase(IMAGE_SCN_MEM_WRITE);
     284         572 : }
     285             : 
     286           1 : void ScalarBitSetTraits<COFF::DLLCharacteristics>::bitset(
     287             :     IO &IO, COFF::DLLCharacteristics &Value) {
     288           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
     289           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
     290           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
     291           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
     292           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
     293           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
     294           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
     295           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
     296           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
     297           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
     298           1 :   BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
     299           1 : }
     300             : #undef BCase
     301             : 
     302             : namespace {
     303             : 
     304             : struct NSectionSelectionType {
     305             :   NSectionSelectionType(IO &)
     306             :       : SelectionType(COFFYAML::COMDATType(0)) {}
     307             :   NSectionSelectionType(IO &, uint8_t C)
     308             :       : SelectionType(COFFYAML::COMDATType(C)) {}
     309             : 
     310         488 :   uint8_t denormalize(IO &) { return SelectionType; }
     311             : 
     312             :   COFFYAML::COMDATType SelectionType;
     313             : };
     314             : 
     315             : struct NWeakExternalCharacteristics {
     316             :   NWeakExternalCharacteristics(IO &)
     317             :       : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
     318             :   NWeakExternalCharacteristics(IO &, uint32_t C)
     319             :       : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
     320             : 
     321           5 :   uint32_t denormalize(IO &) { return Characteristics; }
     322             : 
     323             :   COFFYAML::WeakExternalCharacteristics Characteristics;
     324             : };
     325             : 
     326             : struct NSectionCharacteristics {
     327             :   NSectionCharacteristics(IO &)
     328         526 :       : Characteristics(COFF::SectionCharacteristics(0)) {}
     329             :   NSectionCharacteristics(IO &, uint32_t C)
     330          46 :       : Characteristics(COFF::SectionCharacteristics(C)) {}
     331             : 
     332         526 :   uint32_t denormalize(IO &) { return Characteristics; }
     333             : 
     334             :   COFF::SectionCharacteristics Characteristics;
     335             : };
     336             : 
     337             : struct NAuxTokenType {
     338             :   NAuxTokenType(IO &)
     339             :       : AuxType(COFFYAML::AuxSymbolType(0)) {}
     340             :   NAuxTokenType(IO &, uint8_t C)
     341             :       : AuxType(COFFYAML::AuxSymbolType(C)) {}
     342             : 
     343           0 :   uint32_t denormalize(IO &) { return AuxType; }
     344             : 
     345             :   COFFYAML::AuxSymbolType AuxType;
     346             : };
     347             : 
     348             : struct NStorageClass {
     349        1070 :   NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
     350          89 :   NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
     351             : 
     352        1070 :   uint8_t denormalize(IO &) { return StorageClass; }
     353             : 
     354             :   COFF::SymbolStorageClass StorageClass;
     355             : };
     356             : 
     357             : struct NMachine {
     358         206 :   NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
     359          14 :   NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
     360             : 
     361         206 :   uint16_t denormalize(IO &) { return Machine; }
     362             : 
     363             :   COFF::MachineTypes Machine;
     364             : };
     365             : 
     366             : struct NHeaderCharacteristics {
     367         206 :   NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
     368             :   NHeaderCharacteristics(IO &, uint16_t C)
     369          14 :       : Characteristics(COFF::Characteristics(C)) {}
     370             : 
     371         206 :   uint16_t denormalize(IO &) { return Characteristics; }
     372             : 
     373             :   COFF::Characteristics Characteristics;
     374             : };
     375             : 
     376             : template <typename RelocType>
     377             : struct NType {
     378         614 :   NType(IO &) : Type(RelocType(0)) {}
     379          60 :   NType(IO &, uint16_t T) : Type(RelocType(T)) {}
     380             : 
     381         614 :   uint16_t denormalize(IO &) { return Type; }
     382             : 
     383             :   RelocType Type;
     384             : };
     385             : 
     386             : struct NWindowsSubsystem {
     387           1 :   NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
     388           0 :   NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
     389             : 
     390           1 :   uint16_t denormalize(IO &) { return Subsystem; }
     391             : 
     392             :   COFF::WindowsSubsystem Subsystem;
     393             : };
     394             : 
     395             : struct NDLLCharacteristics {
     396           1 :   NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
     397             :   NDLLCharacteristics(IO &, uint16_t C)
     398           0 :       : Characteristics(COFF::DLLCharacteristics(C)) {}
     399             : 
     400           1 :   uint16_t denormalize(IO &) { return Characteristics; }
     401             : 
     402             :   COFF::DLLCharacteristics Characteristics;
     403             : };
     404             : 
     405             : } // end anonymous namespace
     406             : 
     407         674 : void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
     408             :                                                   COFFYAML::Relocation &Rel) {
     409         674 :   IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
     410         674 :   IO.mapRequired("SymbolName", Rel.SymbolName);
     411             : 
     412         674 :   COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
     413         674 :   if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
     414             :     MappingNormalization<NType<COFF::RelocationTypeI386>, uint16_t> NT(
     415         182 :         IO, Rel.Type);
     416         182 :     IO.mapRequired("Type", NT->Type);
     417         492 :   } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
     418             :     MappingNormalization<NType<COFF::RelocationTypeAMD64>, uint16_t> NT(
     419         432 :         IO, Rel.Type);
     420         432 :     IO.mapRequired("Type", NT->Type);
     421          60 :   } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
     422             :     MappingNormalization<NType<COFF::RelocationTypesARM>, uint16_t> NT(
     423          15 :         IO, Rel.Type);
     424          15 :     IO.mapRequired("Type", NT->Type);
     425          45 :   } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARM64) {
     426             :     MappingNormalization<NType<COFF::RelocationTypesARM64>, uint16_t> NT(
     427          45 :         IO, Rel.Type);
     428          45 :     IO.mapRequired("Type", NT->Type);
     429             :   } else {
     430           0 :     IO.mapRequired("Type", Rel.Type);
     431             :   }
     432         674 : }
     433             : 
     434           0 : void MappingTraits<COFF::DataDirectory>::mapping(IO &IO,
     435             :                                                  COFF::DataDirectory &DD) {
     436           0 :   IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
     437           0 :   IO.mapRequired("Size", DD.Size);
     438           0 : }
     439             : 
     440           1 : void MappingTraits<COFFYAML::PEHeader>::mapping(IO &IO,
     441             :                                                 COFFYAML::PEHeader &PH) {
     442             :   MappingNormalization<NWindowsSubsystem, uint16_t> NWS(IO,
     443           1 :                                                         PH.Header.Subsystem);
     444             :   MappingNormalization<NDLLCharacteristics, uint16_t> NDC(
     445           1 :       IO, PH.Header.DLLCharacteristics);
     446             : 
     447           1 :   IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
     448           1 :   IO.mapRequired("ImageBase", PH.Header.ImageBase);
     449           1 :   IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
     450           1 :   IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
     451           1 :   IO.mapRequired("MajorOperatingSystemVersion",
     452             :                  PH.Header.MajorOperatingSystemVersion);
     453           1 :   IO.mapRequired("MinorOperatingSystemVersion",
     454             :                  PH.Header.MinorOperatingSystemVersion);
     455           1 :   IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
     456           1 :   IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
     457           1 :   IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
     458           1 :   IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
     459           1 :   IO.mapRequired("Subsystem", NWS->Subsystem);
     460           1 :   IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
     461           1 :   IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
     462           1 :   IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
     463           1 :   IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
     464           1 :   IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
     465             : 
     466           1 :   IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
     467           1 :   IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
     468           1 :   IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
     469           1 :   IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
     470           1 :   IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
     471           1 :   IO.mapOptional("BaseRelocationTable",
     472             :                  PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
     473           1 :   IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG_DIRECTORY]);
     474           1 :   IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
     475           1 :   IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
     476           1 :   IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
     477           1 :   IO.mapOptional("LoadConfigTable",
     478             :                  PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
     479           1 :   IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
     480           1 :   IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
     481           1 :   IO.mapOptional("DelayImportDescriptor",
     482             :                  PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
     483           1 :   IO.mapOptional("ClrRuntimeHeader",
     484             :                  PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
     485           1 : }
     486             : 
     487         220 : void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
     488         220 :   MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
     489             :   MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
     490         220 :                                                             H.Characteristics);
     491             : 
     492         220 :   IO.mapRequired("Machine", NM->Machine);
     493         220 :   IO.mapOptional("Characteristics", NC->Characteristics);
     494         220 :   IO.setContext(static_cast<void *>(&H));
     495         220 : }
     496             : 
     497           0 : void MappingTraits<COFF::AuxiliaryFunctionDefinition>::mapping(
     498             :     IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
     499           0 :   IO.mapRequired("TagIndex", AFD.TagIndex);
     500           0 :   IO.mapRequired("TotalSize", AFD.TotalSize);
     501           0 :   IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
     502           0 :   IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
     503           0 : }
     504             : 
     505           0 : void MappingTraits<COFF::AuxiliarybfAndefSymbol>::mapping(
     506             :     IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
     507           0 :   IO.mapRequired("Linenumber", AAS.Linenumber);
     508           0 :   IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
     509           0 : }
     510             : 
     511           6 : void MappingTraits<COFF::AuxiliaryWeakExternal>::mapping(
     512             :     IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
     513             :   MappingNormalization<NWeakExternalCharacteristics, uint32_t> NWEC(
     514           6 :       IO, AWE.Characteristics);
     515           6 :   IO.mapRequired("TagIndex", AWE.TagIndex);
     516           6 :   IO.mapRequired("Characteristics", NWEC->Characteristics);
     517           6 : }
     518             : 
     519         543 : void MappingTraits<COFF::AuxiliarySectionDefinition>::mapping(
     520             :     IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
     521             :   MappingNormalization<NSectionSelectionType, uint8_t> NSST(
     522         543 :       IO, ASD.Selection);
     523             : 
     524         543 :   IO.mapRequired("Length", ASD.Length);
     525         543 :   IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
     526         543 :   IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
     527         543 :   IO.mapRequired("CheckSum", ASD.CheckSum);
     528         543 :   IO.mapRequired("Number", ASD.Number);
     529        1086 :   IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
     530         543 : }
     531             : 
     532           0 : void MappingTraits<COFF::AuxiliaryCLRToken>::mapping(
     533             :     IO &IO, COFF::AuxiliaryCLRToken &ACT) {
     534           0 :   MappingNormalization<NAuxTokenType, uint8_t> NATT(IO, ACT.AuxType);
     535           0 :   IO.mapRequired("AuxType", NATT->AuxType);
     536           0 :   IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
     537           0 : }
     538             : 
     539        1159 : void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S) {
     540        1159 :   MappingNormalization<NStorageClass, uint8_t> NS(IO, S.Header.StorageClass);
     541             : 
     542        1159 :   IO.mapRequired("Name", S.Name);
     543        1159 :   IO.mapRequired("Value", S.Header.Value);
     544        1159 :   IO.mapRequired("SectionNumber", S.Header.SectionNumber);
     545        1159 :   IO.mapRequired("SimpleType", S.SimpleType);
     546        1159 :   IO.mapRequired("ComplexType", S.ComplexType);
     547        1159 :   IO.mapRequired("StorageClass", NS->StorageClass);
     548        1159 :   IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
     549        1159 :   IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
     550        1159 :   IO.mapOptional("WeakExternal", S.WeakExternal);
     551        2318 :   IO.mapOptional("File", S.File, StringRef());
     552        1159 :   IO.mapOptional("SectionDefinition", S.SectionDefinition);
     553        1159 :   IO.mapOptional("CLRToken", S.CLRToken);
     554        1159 : }
     555             : 
     556         572 : void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
     557             :   MappingNormalization<NSectionCharacteristics, uint32_t> NC(
     558         572 :       IO, Sec.Header.Characteristics);
     559         572 :   IO.mapRequired("Name", Sec.Name);
     560         572 :   IO.mapRequired("Characteristics", NC->Characteristics);
     561        1144 :   IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
     562        1144 :   IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
     563        1144 :   IO.mapOptional("Alignment", Sec.Alignment, 0U);
     564             : 
     565             :   // If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the
     566             :   // semantic representation of the symbols/types.  If it is any other kind
     567             :   // of section, just deal in raw bytes.
     568         572 :   IO.mapOptional("SectionData", Sec.SectionData);
     569             :   if (Sec.Name == ".debug$S")
     570          65 :     IO.mapOptional("Subsections", Sec.DebugS);
     571             :   else if (Sec.Name == ".debug$T")
     572          42 :     IO.mapOptional("Types", Sec.DebugT);
     573             :   else if (Sec.Name == ".debug$P")
     574           2 :     IO.mapOptional("PrecompTypes", Sec.DebugP);
     575             :   else if (Sec.Name == ".debug$H")
     576           5 :     IO.mapOptional("GlobalHashes", Sec.DebugH);
     577             : 
     578         572 :   IO.mapOptional("Relocations", Sec.Relocations);
     579         572 : }
     580             : 
     581         220 : void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
     582         440 :   IO.mapTag("!COFF", true);
     583         220 :   IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
     584         220 :   IO.mapRequired("header", Obj.Header);
     585         220 :   IO.mapRequired("sections", Obj.Sections);
     586         220 :   IO.mapRequired("symbols", Obj.Symbols);
     587         220 : }
     588             : 
     589             : } // end namespace yaml
     590             : 
     591             : } // end namespace llvm

Generated by: LCOV version 1.13