From f59a2a86fffa55d5a4f6a2bc339bfa55f4ccf059 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 20 Apr 2013 02:02:25 +0000 Subject: Remove COFFYAML::Header. Instead, use MappingNormalization to directly parse COFF::header. Also change the naming convention of the helper classes to be a bit shorter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179917 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/yaml2obj/yaml2obj.cpp | 55 +++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/yaml2obj/yaml2obj.cpp b/tools/yaml2obj/yaml2obj.cpp index 6748802..5741d95 100644 --- a/tools/yaml2obj/yaml2obj.cpp +++ b/tools/yaml2obj/yaml2obj.cpp @@ -121,11 +121,6 @@ namespace COFFYAML { StringRef Name; }; - struct Header { - COFF::MachineTypes Machine; - COFF::Characteristics Characteristics; - }; - struct Symbol { COFF::SymbolBaseType SimpleType; uint8_t NumberOfAuxSymbols; @@ -138,7 +133,7 @@ namespace COFFYAML { }; struct Object { - Header HeaderData; + COFF::header HeaderData; std::vector
Sections; std::vector Symbols; }; @@ -632,31 +627,57 @@ struct MappingTraits { }; template <> -struct MappingTraits { - static void mapping(IO &IO, COFFYAML::Header &H) { - IO.mapRequired("Machine", H.Machine); - IO.mapOptional("Characteristics", H.Characteristics); +struct MappingTraits { + struct NMachine { + NMachine(IO&) : Machine(COFF::MachineTypes(0)) { + } + NMachine(IO&, uint16_t M) : Machine(COFF::MachineTypes(M)) { + } + uint16_t denormalize(IO &) { + return Machine; + } + COFF::MachineTypes Machine; + }; + + struct NCharacteristics { + NCharacteristics(IO&) : Characteristics(COFF::Characteristics(0)) { + } + NCharacteristics(IO&, uint16_t C) : + Characteristics(COFF::Characteristics(C)) { + } + uint16_t denormalize(IO &) { + return Characteristics; + } + + COFF::Characteristics Characteristics; + }; + + static void mapping(IO &IO, COFF::header &H) { + MappingNormalization NM(IO, H.Machine); + MappingNormalization NC(IO, H.Characteristics); + + IO.mapRequired("Machine", NM->Machine); + IO.mapOptional("Characteristics", NC->Characteristics); } }; template <> struct MappingTraits { - struct NormalizedType { - public: - NormalizedType(IO &) : Type(COFF::RelocationTypeX86(0)) { + struct NType { + NType(IO &) : Type(COFF::RelocationTypeX86(0)) { } - NormalizedType(IO &, uint16_t T) : Type(COFF::RelocationTypeX86(T)) { + NType(IO &, uint16_t T) : Type(COFF::RelocationTypeX86(T)) { } uint16_t denormalize(IO &) { return Type; } - COFF::RelocationTypeX86 Type; }; + static void mapping(IO &IO, COFF::relocation &Rel) { - MappingNormalization foo(IO, Rel.Type); + MappingNormalization NT(IO, Rel.Type); - IO.mapRequired("Type", foo->Type); + IO.mapRequired("Type", NT->Type); IO.mapRequired("VirtualAddress", Rel.VirtualAddress); IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex); } -- cgit v1.1