[llvm] r179917 - Remove COFFYAML::Header.

Rafael Espindola rafael.espindola at gmail.com
Fri Apr 19 19:02:25 PDT 2013


Author: rafael
Date: Fri Apr 19 21:02:25 2013
New Revision: 179917

URL: http://llvm.org/viewvc/llvm-project?rev=179917&view=rev
Log:
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.

Modified:
    llvm/trunk/tools/yaml2obj/yaml2obj.cpp

Modified: llvm/trunk/tools/yaml2obj/yaml2obj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.cpp?rev=179917&r1=179916&r2=179917&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2obj.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp Fri Apr 19 21:02:25 2013
@@ -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<Section> Sections;
     std::vector<Symbol> Symbols;
   };
@@ -632,31 +627,57 @@ struct MappingTraits<COFFYAML::Symbol> {
 };
 
 template <>
-struct MappingTraits<COFFYAML::Header> {
-  static void mapping(IO &IO, COFFYAML::Header &H) {
-    IO.mapRequired("Machine", H.Machine);
-    IO.mapOptional("Characteristics", H.Characteristics);
+struct MappingTraits<COFF::header> {
+  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<NMachine, uint16_t> NM(IO, H.Machine);
+    MappingNormalization<NCharacteristics, uint16_t> NC(IO, H.Characteristics);
+
+    IO.mapRequired("Machine", NM->Machine);
+    IO.mapOptional("Characteristics", NC->Characteristics);
   }
 };
 
 template <>
 struct MappingTraits<COFF::relocation> {
-  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<NormalizedType, uint16_t> foo(IO, Rel.Type);
+    MappingNormalization<NType, uint16_t> NT(IO, Rel.Type);
 
-    IO.mapRequired("Type", foo->Type);
+    IO.mapRequired("Type", NT->Type);
     IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
     IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
   }





More information about the llvm-commits mailing list