[llvm] r182169 - Convert obj2yaml to use yamlio.
Rafael EspĂndola
rafael.espindola at gmail.com
Tue May 21 11:55:19 PDT 2013
Should be fixed in r182405. Sorry for the breakage.
On 19 May 2013 11:01, Bob Wilson <bob.wilson at apple.com> wrote:
> Rafael, Object/obj2yaml.test is failing now on some of our buildbots. It
> passes on OS X if you build with libstdc++ but fails if you use libc++. The
> output shows the SectionData with a bunch of binary characters when using
> libc++.
>
> I've temporarily disabled the test in svn r182212. Let me know if you need
> help reproducing the issue.
>
>
> On May 17, 2013, at 3:58 PM, Rafael Espindola <rafael.espindola at gmail.com>
> wrote:
>
> Author: rafael
> Date: Fri May 17 17:58:42 2013
> New Revision: 182169
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182169&view=rev
> Log:
> Convert obj2yaml to use yamlio.
>
> Added:
> llvm/trunk/include/llvm/Object/COFFYaml.h
> llvm/trunk/lib/Object/COFFYAML.cpp
> Modified:
> llvm/trunk/lib/Object/CMakeLists.txt
> llvm/trunk/test/Object/obj2yaml.test
> llvm/trunk/tools/obj2yaml/coff2yaml.cpp
> llvm/trunk/tools/yaml2obj/CMakeLists.txt
> llvm/trunk/tools/yaml2obj/yaml2obj.cpp
>
> Added: llvm/trunk/include/llvm/Object/COFFYaml.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFFYaml.h?rev=182169&view=auto
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/COFFYaml.h (added)
> +++ llvm/trunk/include/llvm/Object/COFFYaml.h Fri May 17 17:58:42 2013
> @@ -0,0 +1,136 @@
> +//===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++
> -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file declares classes for handling the YAML representation of COFF.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLVM_OBJECT_COFFYAML_H
> +#define LLVM_OBJECT_COFFYAML_H
> +
> +
> +#include "llvm/Support/COFF.h"
> +#include "llvm/Support/YAMLTraits.h"
> +
> +namespace llvm {
> +
> +namespace COFF {
> +inline Characteristics operator|(Characteristics a, Characteristics b) {
> + uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
> + return static_cast<Characteristics>(Ret);
> +}
> +
> +inline SectionCharacteristics operator|(SectionCharacteristics a,
> + SectionCharacteristics b) {
> + uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
> + return static_cast<SectionCharacteristics>(Ret);
> +}
> +}
> +
> +// The structure of the yaml files is not an exact 1:1 match to COFF. In
> order
> +// to use yaml::IO, we use these structures which are closer to the source.
> +namespace COFFYAML {
> + struct Section {
> + COFF::section Header;
> + unsigned Alignment;
> + StringRef SectionData;
> + std::vector<COFF::relocation> Relocations;
> + StringRef Name;
> + Section();
> + };
> +
> + struct Symbol {
> + COFF::symbol Header;
> + COFF::SymbolBaseType SimpleType;
> + COFF::SymbolComplexType ComplexType;
> + StringRef AuxiliaryData;
> + StringRef Name;
> + Symbol();
> + };
> +
> + struct Object {
> + COFF::header Header;
> + std::vector<Section> Sections;
> + std::vector<Symbol> Symbols;
> + Object();
> + };
> +}
> +}
> +
> +LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
> +LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
> +LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
> +
> +namespace llvm {
> +namespace yaml {
> +
> +template <>
> +struct ScalarEnumerationTraits<COFF::MachineTypes> {
> + static void enumeration(IO &IO, COFF::MachineTypes &Value);
> +};
> +
> +template <>
> +struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
> + static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
> +};
> +
> +template <>
> +struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
> + static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
> +};
> +
> +template <>
> +struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
> + static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
> +};
> +
> +template <>
> +struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
> + static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
> +};
> +
> +template <>
> +struct ScalarBitSetTraits<COFF::Characteristics> {
> + static void bitset(IO &IO, COFF::Characteristics &Value);
> +};
> +
> +template <>
> +struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
> + static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
> +};
> +
> +template <>
> +struct MappingTraits<COFF::relocation> {
> + static void mapping(IO &IO, COFF::relocation &Rel);
> +};
> +
> +template <>
> +struct MappingTraits<COFF::header> {
> + static void mapping(IO &IO, COFF::header &H);
> +};
> +
> +template <>
> +struct MappingTraits<COFFYAML::Symbol> {
> + static void mapping(IO &IO, COFFYAML::Symbol &S);
> +};
> +
> +template <>
> +struct MappingTraits<COFFYAML::Section> {
> + static void mapping(IO &IO, COFFYAML::Section &Sec);
> +};
> +
> +template <>
> +struct MappingTraits<COFFYAML::Object> {
> + static void mapping(IO &IO, COFFYAML::Object &Obj);
> +};
> +
> +} // end namespace yaml
> +} // end namespace llvm
> +
> +#endif
>
> Modified: llvm/trunk/lib/Object/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/CMakeLists.txt?rev=182169&r1=182168&r2=182169&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/CMakeLists.txt (original)
> +++ llvm/trunk/lib/Object/CMakeLists.txt Fri May 17 17:58:42 2013
> @@ -2,6 +2,7 @@ add_llvm_library(LLVMObject
> Archive.cpp
> Binary.cpp
> COFFObjectFile.cpp
> + COFFYAML.cpp
> ELFObjectFile.cpp
> Error.cpp
> MachOObjectFile.cpp
>
> Added: llvm/trunk/lib/Object/COFFYAML.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFYAML.cpp?rev=182169&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Object/COFFYAML.cpp (added)
> +++ llvm/trunk/lib/Object/COFFYAML.cpp Fri May 17 17:58:42 2013
> @@ -0,0 +1,279 @@
> +//===- COFFYAML.cpp - COFF YAMLIO implementation
> --------------------------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file defines classes for handling the YAML representation of COFF.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "llvm/Object/COFFYaml.h"
> +
> +#define ECase(X) IO.enumCase(Value, #X, COFF::X);
> +namespace llvm {
> +
> +namespace COFFYAML {
> +Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
> +Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
> +Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
> +}
> +
> +namespace yaml {
> +void ScalarEnumerationTraits<COFF::MachineTypes>::enumeration(
> + IO &IO, COFF::MachineTypes &Value) {
> + ECase(IMAGE_FILE_MACHINE_UNKNOWN);
> + ECase(IMAGE_FILE_MACHINE_AM33);
> + ECase(IMAGE_FILE_MACHINE_AMD64);
> + ECase(IMAGE_FILE_MACHINE_ARM);
> + ECase(IMAGE_FILE_MACHINE_ARMV7);
> + ECase(IMAGE_FILE_MACHINE_EBC);
> + ECase(IMAGE_FILE_MACHINE_I386);
> + ECase(IMAGE_FILE_MACHINE_IA64);
> + ECase(IMAGE_FILE_MACHINE_M32R);
> + ECase(IMAGE_FILE_MACHINE_MIPS16);
> + ECase(IMAGE_FILE_MACHINE_MIPSFPU);
> + ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
> + ECase(IMAGE_FILE_MACHINE_POWERPC);
> + ECase(IMAGE_FILE_MACHINE_POWERPCFP);
> + ECase(IMAGE_FILE_MACHINE_R4000);
> + ECase(IMAGE_FILE_MACHINE_SH3);
> + ECase(IMAGE_FILE_MACHINE_SH3DSP);
> + ECase(IMAGE_FILE_MACHINE_SH4);
> + ECase(IMAGE_FILE_MACHINE_SH5);
> + ECase(IMAGE_FILE_MACHINE_THUMB);
> + ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
> +}
> +
> +void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
> + IO &IO, COFF::SymbolBaseType &Value) {
> + ECase(IMAGE_SYM_TYPE_NULL);
> + ECase(IMAGE_SYM_TYPE_VOID);
> + ECase(IMAGE_SYM_TYPE_CHAR);
> + ECase(IMAGE_SYM_TYPE_SHORT);
> + ECase(IMAGE_SYM_TYPE_INT);
> + ECase(IMAGE_SYM_TYPE_LONG);
> + ECase(IMAGE_SYM_TYPE_FLOAT);
> + ECase(IMAGE_SYM_TYPE_DOUBLE);
> + ECase(IMAGE_SYM_TYPE_STRUCT);
> + ECase(IMAGE_SYM_TYPE_UNION);
> + ECase(IMAGE_SYM_TYPE_ENUM);
> + ECase(IMAGE_SYM_TYPE_MOE);
> + ECase(IMAGE_SYM_TYPE_BYTE);
> + ECase(IMAGE_SYM_TYPE_WORD);
> + ECase(IMAGE_SYM_TYPE_UINT);
> + ECase(IMAGE_SYM_TYPE_DWORD);
> +}
> +
> +void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
> + IO &IO, COFF::SymbolStorageClass &Value) {
> + ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
> + ECase(IMAGE_SYM_CLASS_NULL);
> + ECase(IMAGE_SYM_CLASS_AUTOMATIC);
> + ECase(IMAGE_SYM_CLASS_EXTERNAL);
> + ECase(IMAGE_SYM_CLASS_STATIC);
> + ECase(IMAGE_SYM_CLASS_REGISTER);
> + ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
> + ECase(IMAGE_SYM_CLASS_LABEL);
> + ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
> + ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
> + ECase(IMAGE_SYM_CLASS_ARGUMENT);
> + ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
> + ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
> + ECase(IMAGE_SYM_CLASS_UNION_TAG);
> + ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
> + ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
> + ECase(IMAGE_SYM_CLASS_ENUM_TAG);
> + ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
> + ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
> + ECase(IMAGE_SYM_CLASS_BIT_FIELD);
> + ECase(IMAGE_SYM_CLASS_BLOCK);
> + ECase(IMAGE_SYM_CLASS_FUNCTION);
> + ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
> + ECase(IMAGE_SYM_CLASS_FILE);
> + ECase(IMAGE_SYM_CLASS_SECTION);
> + ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
> + ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
> +}
> +
> +void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
> + IO &IO, COFF::SymbolComplexType &Value) {
> + ECase(IMAGE_SYM_DTYPE_NULL);
> + ECase(IMAGE_SYM_DTYPE_POINTER);
> + ECase(IMAGE_SYM_DTYPE_FUNCTION);
> + ECase(IMAGE_SYM_DTYPE_ARRAY);
> +}
> +
> +void ScalarEnumerationTraits<COFF::RelocationTypeX86>::enumeration(
> + IO &IO, COFF::RelocationTypeX86 &Value) {
> + ECase(IMAGE_REL_I386_ABSOLUTE);
> + ECase(IMAGE_REL_I386_DIR16);
> + ECase(IMAGE_REL_I386_REL16);
> + ECase(IMAGE_REL_I386_DIR32);
> + ECase(IMAGE_REL_I386_DIR32NB);
> + ECase(IMAGE_REL_I386_SEG12);
> + ECase(IMAGE_REL_I386_SECTION);
> + ECase(IMAGE_REL_I386_SECREL);
> + ECase(IMAGE_REL_I386_TOKEN);
> + ECase(IMAGE_REL_I386_SECREL7);
> + ECase(IMAGE_REL_I386_REL32);
> + ECase(IMAGE_REL_AMD64_ABSOLUTE);
> + ECase(IMAGE_REL_AMD64_ADDR64);
> + ECase(IMAGE_REL_AMD64_ADDR32);
> + ECase(IMAGE_REL_AMD64_ADDR32NB);
> + ECase(IMAGE_REL_AMD64_REL32);
> + ECase(IMAGE_REL_AMD64_REL32_1);
> + ECase(IMAGE_REL_AMD64_REL32_2);
> + ECase(IMAGE_REL_AMD64_REL32_3);
> + ECase(IMAGE_REL_AMD64_REL32_4);
> + ECase(IMAGE_REL_AMD64_REL32_5);
> + ECase(IMAGE_REL_AMD64_SECTION);
> + ECase(IMAGE_REL_AMD64_SECREL);
> + ECase(IMAGE_REL_AMD64_SECREL7);
> + ECase(IMAGE_REL_AMD64_TOKEN);
> + ECase(IMAGE_REL_AMD64_SREL32);
> + ECase(IMAGE_REL_AMD64_PAIR);
> + ECase(IMAGE_REL_AMD64_SSPAN32);
> +}
> +#undef ECase
> +
> +#define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
> +void ScalarBitSetTraits<COFF::Characteristics>::bitset(
> + IO &IO, COFF::Characteristics &Value) {
> + BCase(IMAGE_FILE_RELOCS_STRIPPED);
> + BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
> + BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
> + BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
> + BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
> + BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
> + BCase(IMAGE_FILE_BYTES_REVERSED_LO);
> + BCase(IMAGE_FILE_32BIT_MACHINE);
> + BCase(IMAGE_FILE_DEBUG_STRIPPED);
> + BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
> + BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
> + BCase(IMAGE_FILE_SYSTEM);
> + BCase(IMAGE_FILE_DLL);
> + BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
> + BCase(IMAGE_FILE_BYTES_REVERSED_HI);
> +}
> +
> +void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
> + IO &IO, COFF::SectionCharacteristics &Value) {
> + BCase(IMAGE_SCN_TYPE_NO_PAD);
> + BCase(IMAGE_SCN_CNT_CODE);
> + BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
> + BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
> + BCase(IMAGE_SCN_LNK_OTHER);
> + BCase(IMAGE_SCN_LNK_INFO);
> + BCase(IMAGE_SCN_LNK_REMOVE);
> + BCase(IMAGE_SCN_LNK_COMDAT);
> + BCase(IMAGE_SCN_GPREL);
> + BCase(IMAGE_SCN_MEM_PURGEABLE);
> + BCase(IMAGE_SCN_MEM_16BIT);
> + BCase(IMAGE_SCN_MEM_LOCKED);
> + BCase(IMAGE_SCN_MEM_PRELOAD);
> + BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
> + BCase(IMAGE_SCN_MEM_DISCARDABLE);
> + BCase(IMAGE_SCN_MEM_NOT_CACHED);
> + BCase(IMAGE_SCN_MEM_NOT_PAGED);
> + BCase(IMAGE_SCN_MEM_SHARED);
> + BCase(IMAGE_SCN_MEM_EXECUTE);
> + BCase(IMAGE_SCN_MEM_READ);
> + BCase(IMAGE_SCN_MEM_WRITE);
> +}
> +#undef BCase
> +
> +namespace {
> +struct NSectionCharacteristics {
> + NSectionCharacteristics(IO &)
> + : Characteristics(COFF::SectionCharacteristics(0)) {}
> + NSectionCharacteristics(IO &, uint32_t C)
> + : Characteristics(COFF::SectionCharacteristics(C)) {}
> + uint32_t denormalize(IO &) { return Characteristics; }
> + COFF::SectionCharacteristics Characteristics;
> +};
> +
> +struct NStorageClass {
> + NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
> + NStorageClass(IO &, uint8_t S) :
> StorageClass(COFF::SymbolStorageClass(S)) {}
> + uint8_t denormalize(IO &) { return StorageClass; }
> +
> + COFF::SymbolStorageClass StorageClass;
> +};
> +
> +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 NHeaderCharacteristics {
> + NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0))
> {}
> + NHeaderCharacteristics(IO &, uint16_t C)
> + : Characteristics(COFF::Characteristics(C)) {}
> + uint16_t denormalize(IO &) { return Characteristics; }
> +
> + COFF::Characteristics Characteristics;
> +};
> +
> +struct NType {
> + NType(IO &) : Type(COFF::RelocationTypeX86(0)) {}
> + NType(IO &, uint16_t T) : Type(COFF::RelocationTypeX86(T)) {}
> + uint16_t denormalize(IO &) { return Type; }
> + COFF::RelocationTypeX86 Type;
> +};
> +
> +}
> +
> +void MappingTraits<COFF::relocation>::mapping(IO &IO, COFF::relocation
> &Rel) {
> + MappingNormalization<NType, uint16_t> NT(IO, Rel.Type);
> +
> + IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
> + IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
> + IO.mapRequired("Type", NT->Type);
> +}
> +
> +void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
> + MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
> + MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
> +
> H.Characteristics);
> +
> + IO.mapRequired("Machine", NM->Machine);
> + IO.mapOptional("Characteristics", NC->Characteristics);
> +}
> +
> +void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S)
> {
> + MappingNormalization<NStorageClass, uint8_t> NS(IO,
> S.Header.StorageClass);
> +
> + IO.mapRequired("Name", S.Name);
> + IO.mapRequired("Value", S.Header.Value);
> + IO.mapRequired("SectionNumber", S.Header.SectionNumber);
> + IO.mapRequired("SimpleType", S.SimpleType);
> + IO.mapRequired("ComplexType", S.ComplexType);
> + IO.mapRequired("StorageClass", NS->StorageClass);
> + IO.mapOptional("NumberOfAuxSymbols", S.Header.NumberOfAuxSymbols);
> + IO.mapOptional("AuxiliaryData", S.AuxiliaryData);
> +}
> +
> +void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section
> &Sec) {
> + MappingNormalization<NSectionCharacteristics, uint32_t> NC(
> + IO, Sec.Header.Characteristics);
> + IO.mapRequired("Name", Sec.Name);
> + IO.mapRequired("Characteristics", NC->Characteristics);
> + IO.mapOptional("Alignment", Sec.Alignment);
> + IO.mapRequired("SectionData", Sec.SectionData);
> + IO.mapOptional("Relocations", Sec.Relocations);
> +}
> +
> +void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object
> &Obj) {
> + IO.mapRequired("header", Obj.Header);
> + IO.mapRequired("sections", Obj.Sections);
> + IO.mapRequired("symbols", Obj.Symbols);
> +}
> +
> +}
> +}
>
> Modified: llvm/trunk/test/Object/obj2yaml.test
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/obj2yaml.test?rev=182169&r1=182168&r2=182169&view=diff
> ==============================================================================
> --- llvm/trunk/test/Object/obj2yaml.test (original)
> +++ llvm/trunk/test/Object/obj2yaml.test Fri May 17 17:58:42 2013
> @@ -2,169 +2,151 @@ RUN: obj2yaml %p/Inputs/trivial-object-t
> RUN: obj2yaml %p/Inputs/trivial-object-test.coff-x86-64 | FileCheck %s
> --check-prefix COFF-X86-64
>
>
> -COFF-I386: header: !Header
> -COFF-I386-NEXT: Machine: IMAGE_FILE_MACHINE_I386 # (0x14c)
> +COFF-I386: header:
> +COFF-I386-NEXT: Machine: IMAGE_FILE_MACHINE_I386
>
> COFF-I386: sections:
> -COFF-I386-NEXT: - !Section
> -COFF-I386-NEXT: Name: .text
> -COFF-I386-NEXT: Characteristics: [IMAGE_SCN_CNT_CODE,
> IMAGE_SCN_ALIGN_16BYTES, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ, ] #
> 0x60500020
> -COFF-I386-NEXT: SectionData: !hex
> "83EC0CC744240800000000C7042400000000E800000000E8000000008B44240883C40CC3" #
> |....D$.......$...............D$.....|
> +COFF-I386-NEXT: - Name: .text
> +COFF-I386-NEXT: Characteristics: [ IMAGE_SCN_CNT_CODE,
> IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
> +COFF-I386-NEXT: Alignment: 16
> +COFF-I386-NEXT: SectionData:
> 83EC0CC744240800000000C7042400000000E800000000E8000000008B44240883C40CC3
>
> COFF-I386: Relocations:
> -COFF-I386-NEXT: - !Relocation
> -COFF-I386-NEXT: VirtualAddress: 0xe
> +COFF-I386-NEXT: - VirtualAddress: 14
> COFF-I386-NEXT: SymbolTableIndex: 5
> COFF-I386-NEXT: Type: IMAGE_REL_I386_DIR32
>
> -COFF-I386: - !Relocation
> -COFF-I386-NEXT: VirtualAddress: 0x13
> +COFF-I386: - VirtualAddress: 19
> COFF-I386-NEXT: SymbolTableIndex: 6
> COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
>
> -COFF-I386: - !Relocation
> -COFF-I386-NEXT: VirtualAddress: 0x18
> +COFF-I386: - VirtualAddress: 24
> COFF-I386-NEXT: SymbolTableIndex: 7
> COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
>
> -COFF-I386: - !Section
> -COFF-I386-NEXT: Name: .data
> -COFF-I386-NEXT: Characteristics: [IMAGE_SCN_CNT_INITIALIZED_DATA,
> IMAGE_SCN_ALIGN_1BYTES, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE, ] #
> 0xc0100040
> -COFF-I386-NEXT: SectionData: !hex "48656C6C6F20576F726C642100" # |Hello
> World!.|
> +COFF-I386: - Name: .data
> +COFF-I386-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA,
> IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
> +COFF-I386-NEXT: Alignment: 1
> +COFF-I386-NEXT: SectionData: 48656C6C6F20576F726C642100
>
> COFF-I386: symbols:
> -COFF-I386-NEXT: - !Symbol
> -COFF-I386-NEXT: Name: .text
> +COFF-I386-NEXT: - Name: .text
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 1
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
> COFF-I386-NEXT: NumberOfAuxSymbols: 1
> -COFF-I386-NEXT: AuxillaryData: !hex
> "240000000300000000000000010000000000" # |$.................|
> +COFF-I386-NEXT: AuxiliaryData: 240000000300000000000000010000000000
>
> -COFF-I386: - !Symbol
> -COFF-I386-NEXT: Name: .data
> +COFF-I386: - Name: .data
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 2
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
> COFF-I386-NEXT: NumberOfAuxSymbols: 1
> -COFF-I386-NEXT: AuxillaryData: !hex
> "0D0000000000000000000000020000000000" # |..................|
> +COFF-I386-NEXT: AuxiliaryData: 0D0000000000000000000000020000000000
>
> -COFF-I386: - !Symbol
> -COFF-I386-NEXT: Name: _main
> +COFF-I386: - Name: _main
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 1
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_FUNCTION # (2)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_FUNCTION
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
> -COFF-I386: - !Symbol
> -COFF-I386-NEXT: Name: L_.str
> +COFF-I386: - Name: L_.str
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 2
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
>
> -COFF-I386: - !Symbol
> -COFF-I386-NEXT: Name: _puts
> +COFF-I386: - Name: _puts
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 0
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
> -COFF-I386: - !Symbol
> -COFF-I386-NEXT: Name: _SomeOtherFunction
> +COFF-I386: - Name: _SomeOtherFunction
> COFF-I386-NEXT: Value: 0
> COFF-I386-NEXT: SectionNumber: 0
> -COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-I386-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-I386-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-I386-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
>
> -COFF-X86-64: header: !Header
> -COFF-X86-64-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64 # (0x8664)
> +COFF-X86-64: header:
> +COFF-X86-64-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64
>
> COFF-X86-64: sections:
> -COFF-X86-64-NEXT: - !Section
> -COFF-X86-64-NEXT: Name: .text
> -COFF-X86-64-NEXT: Characteristics: [IMAGE_SCN_CNT_CODE,
> IMAGE_SCN_ALIGN_16BYTES, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ, ] #
> 0x60500020
> -COFF-X86-64-NEXT: SectionData: !hex
> "4883EC28C744242400000000488D0D00000000E800000000E8000000008B4424244883C428C3"
> # |H..(.D$$....H.................D$$H..(.|
> +COFF-X86-64-NEXT: - Name: .text
> +COFF-X86-64-NEXT: Characteristics: [ IMAGE_SCN_CNT_CODE,
> IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
> +COFF-X86-64-NEXT: Alignment: 16
> +COFF-X86-64-NEXT: SectionData:
> 4883EC28C744242400000000488D0D00000000E800000000E8000000008B4424244883C428C3
>
> COFF-X86-64: Relocations:
> -COFF-X86-64-NEXT: - !Relocation
> -COFF-X86-64-NEXT: VirtualAddress: 0xf
> +COFF-X86-64-NEXT: - VirtualAddress: 15
> COFF-X86-64-NEXT: SymbolTableIndex: 5
> COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
>
> -COFF-X86-64: - !Relocation
> -COFF-X86-64-NEXT: VirtualAddress: 0x14
> +COFF-X86-64: - VirtualAddress: 20
> COFF-X86-64-NEXT: SymbolTableIndex: 6
> COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
>
> -COFF-X86-64: - !Relocation
> -COFF-X86-64-NEXT: VirtualAddress: 0x19
> +COFF-X86-64: - VirtualAddress: 25
> COFF-X86-64-NEXT: SymbolTableIndex: 7
> COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
>
> -COFF-X86-64: - !Section
> -COFF-X86-64-NEXT: Name: .data
> -COFF-X86-64-NEXT: Characteristics: [IMAGE_SCN_CNT_INITIALIZED_DATA,
> IMAGE_SCN_ALIGN_1BYTES, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE, ] #
> 0xc0100040
> -COFF-X86-64-NEXT: SectionData: !hex "48656C6C6F20576F726C642100" #
> |Hello World!.|
> +COFF-X86-64: - Name: .data
> +COFF-X86-64-NEXT: Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA,
> IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
> +COFF-X86-64-NEXT: Alignment: 1
> +COFF-X86-64-NEXT: SectionData: 48656C6C6F20576F726C642100
>
> COFF-X86-64: symbols:
> -COFF-X86-64-NEXT: - !Symbol
> -COFF-X86-64-NEXT: Name: .text
> +COFF-X86-64-NEXT: - Name: .text
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 1
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
> COFF-X86-64-NEXT: NumberOfAuxSymbols: 1
> -COFF-X86-64-NEXT: AuxillaryData: !hex
> "260000000300000000000000010000000000" # |&.................|
> +COFF-X86-64-NEXT: AuxiliaryData: 260000000300000000000000010000000000
>
> -COFF-X86-64: - !Symbol
> -COFF-X86-64-NEXT: Name: .data
> +COFF-X86-64: - Name: .data
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 2
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
> COFF-X86-64-NEXT: NumberOfAuxSymbols: 1
> -COFF-X86-64-NEXT: AuxillaryData: !hex
> "0D0000000000000000000000020000000000" # |..................|
> +COFF-X86-64-NEXT: AuxiliaryData: 0D0000000000000000000000020000000000
>
> -COFF-X86-64: - !Symbol
> -COFF-X86-64-NEXT: Name: main
> +COFF-X86-64: - Name: main
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 1
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
> -COFF-X86-64: - !Symbol
> -COFF-X86-64-NEXT: Name: L.str
> +COFF-X86-64: - Name: L.str
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 2
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_STATIC
>
> -COFF-X86-64: - !Symbol
> -COFF-X86-64-NEXT: Name: puts
> +COFF-X86-64: - Name: puts
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 0
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
> -COFF-X86-64: - !Symbol
> -COFF-X86-64-NEXT: Name: SomeOtherFunction
> +COFF-X86-64: - Name: SomeOtherFunction
> COFF-X86-64-NEXT: Value: 0
> COFF-X86-64-NEXT: SectionNumber: 0
> -COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL # (0)
> -COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
> -COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
> +COFF-X86-64-NEXT: SimpleType: IMAGE_SYM_TYPE_NULL
> +COFF-X86-64-NEXT: ComplexType: IMAGE_SYM_DTYPE_NULL
> +COFF-X86-64-NEXT: StorageClass: IMAGE_SYM_CLASS_EXTERNAL
>
> Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=182169&r1=182168&r2=182169&view=diff
> ==============================================================================
> --- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
> +++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Fri May 17 17:58:42 2013
> @@ -9,346 +9,124 @@
>
> #include "obj2yaml.h"
> #include "llvm/Object/COFF.h"
> +#include "llvm/Object/COFFYaml.h"
> +#include "llvm/Support/ErrorHandling.h"
> +#include "llvm/Support/YAMLTraits.h"
>
> using namespace llvm;
>
> -template <typename One, typename Two>
> -struct pod_pair { // I'd much rather use std::pair, but it's not a POD
> - One first;
> - Two second;
> -};
> -
> -#define STRING_PAIR(x) {COFF::x, #x}
> -static const pod_pair<COFF::MachineTypes, const char *>
> -MachineTypePairs [] = {
> - STRING_PAIR(IMAGE_FILE_MACHINE_UNKNOWN),
> - STRING_PAIR(IMAGE_FILE_MACHINE_AM33),
> - STRING_PAIR(IMAGE_FILE_MACHINE_AMD64),
> - STRING_PAIR(IMAGE_FILE_MACHINE_ARM),
> - STRING_PAIR(IMAGE_FILE_MACHINE_ARMV7),
> - STRING_PAIR(IMAGE_FILE_MACHINE_EBC),
> - STRING_PAIR(IMAGE_FILE_MACHINE_I386),
> - STRING_PAIR(IMAGE_FILE_MACHINE_IA64),
> - STRING_PAIR(IMAGE_FILE_MACHINE_M32R),
> - STRING_PAIR(IMAGE_FILE_MACHINE_MIPS16),
> - STRING_PAIR(IMAGE_FILE_MACHINE_MIPSFPU),
> - STRING_PAIR(IMAGE_FILE_MACHINE_MIPSFPU16),
> - STRING_PAIR(IMAGE_FILE_MACHINE_POWERPC),
> - STRING_PAIR(IMAGE_FILE_MACHINE_POWERPCFP),
> - STRING_PAIR(IMAGE_FILE_MACHINE_R4000),
> - STRING_PAIR(IMAGE_FILE_MACHINE_SH3),
> - STRING_PAIR(IMAGE_FILE_MACHINE_SH3DSP),
> - STRING_PAIR(IMAGE_FILE_MACHINE_SH4),
> - STRING_PAIR(IMAGE_FILE_MACHINE_SH5),
> - STRING_PAIR(IMAGE_FILE_MACHINE_THUMB),
> - STRING_PAIR(IMAGE_FILE_MACHINE_WCEMIPSV2)
> -};
> -
> -static const pod_pair<COFF::SectionCharacteristics, const char *>
> -SectionCharacteristicsPairs1 [] = {
> - STRING_PAIR(IMAGE_SCN_TYPE_NO_PAD),
> - STRING_PAIR(IMAGE_SCN_CNT_CODE),
> - STRING_PAIR(IMAGE_SCN_CNT_INITIALIZED_DATA),
> - STRING_PAIR(IMAGE_SCN_CNT_UNINITIALIZED_DATA),
> - STRING_PAIR(IMAGE_SCN_LNK_OTHER),
> - STRING_PAIR(IMAGE_SCN_LNK_INFO),
> - STRING_PAIR(IMAGE_SCN_LNK_REMOVE),
> - STRING_PAIR(IMAGE_SCN_LNK_COMDAT),
> - STRING_PAIR(IMAGE_SCN_GPREL),
> - STRING_PAIR(IMAGE_SCN_MEM_PURGEABLE),
> - STRING_PAIR(IMAGE_SCN_MEM_16BIT),
> - STRING_PAIR(IMAGE_SCN_MEM_LOCKED),
> - STRING_PAIR(IMAGE_SCN_MEM_PRELOAD)
> -};
> -
> -static const pod_pair<COFF::SectionCharacteristics, const char *>
> -SectionCharacteristicsPairsAlignment [] = {
> - STRING_PAIR(IMAGE_SCN_ALIGN_1BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_2BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_4BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_8BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_16BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_32BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_64BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_128BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_256BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_512BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_1024BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_2048BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_4096BYTES),
> - STRING_PAIR(IMAGE_SCN_ALIGN_8192BYTES)
> -};
> -
> -static const pod_pair<COFF::SectionCharacteristics, const char *>
> -SectionCharacteristicsPairs2 [] = {
> - STRING_PAIR(IMAGE_SCN_LNK_NRELOC_OVFL),
> - STRING_PAIR(IMAGE_SCN_MEM_DISCARDABLE),
> - STRING_PAIR(IMAGE_SCN_MEM_NOT_CACHED),
> - STRING_PAIR(IMAGE_SCN_MEM_NOT_PAGED),
> - STRING_PAIR(IMAGE_SCN_MEM_SHARED),
> - STRING_PAIR(IMAGE_SCN_MEM_EXECUTE),
> - STRING_PAIR(IMAGE_SCN_MEM_READ),
> - STRING_PAIR(IMAGE_SCN_MEM_WRITE)
> -};
> -
> -static const pod_pair<COFF::SymbolBaseType, const char *>
> -SymbolBaseTypePairs [] = {
> - STRING_PAIR(IMAGE_SYM_TYPE_NULL),
> - STRING_PAIR(IMAGE_SYM_TYPE_VOID),
> - STRING_PAIR(IMAGE_SYM_TYPE_CHAR),
> - STRING_PAIR(IMAGE_SYM_TYPE_SHORT),
> - STRING_PAIR(IMAGE_SYM_TYPE_INT),
> - STRING_PAIR(IMAGE_SYM_TYPE_LONG),
> - STRING_PAIR(IMAGE_SYM_TYPE_FLOAT),
> - STRING_PAIR(IMAGE_SYM_TYPE_DOUBLE),
> - STRING_PAIR(IMAGE_SYM_TYPE_STRUCT),
> - STRING_PAIR(IMAGE_SYM_TYPE_UNION),
> - STRING_PAIR(IMAGE_SYM_TYPE_ENUM),
> - STRING_PAIR(IMAGE_SYM_TYPE_MOE),
> - STRING_PAIR(IMAGE_SYM_TYPE_BYTE),
> - STRING_PAIR(IMAGE_SYM_TYPE_WORD),
> - STRING_PAIR(IMAGE_SYM_TYPE_UINT),
> - STRING_PAIR(IMAGE_SYM_TYPE_DWORD)
> -};
> -
> -static const pod_pair<COFF::SymbolComplexType, const char *>
> -SymbolComplexTypePairs [] = {
> - STRING_PAIR(IMAGE_SYM_DTYPE_NULL),
> - STRING_PAIR(IMAGE_SYM_DTYPE_POINTER),
> - STRING_PAIR(IMAGE_SYM_DTYPE_FUNCTION),
> - STRING_PAIR(IMAGE_SYM_DTYPE_ARRAY),
> -};
> -
> -static const pod_pair<COFF::SymbolStorageClass, const char *>
> -SymbolStorageClassPairs [] = {
> - STRING_PAIR(IMAGE_SYM_CLASS_END_OF_FUNCTION),
> - STRING_PAIR(IMAGE_SYM_CLASS_NULL),
> - STRING_PAIR(IMAGE_SYM_CLASS_AUTOMATIC),
> - STRING_PAIR(IMAGE_SYM_CLASS_EXTERNAL),
> - STRING_PAIR(IMAGE_SYM_CLASS_STATIC),
> - STRING_PAIR(IMAGE_SYM_CLASS_REGISTER),
> - STRING_PAIR(IMAGE_SYM_CLASS_EXTERNAL_DEF),
> - STRING_PAIR(IMAGE_SYM_CLASS_LABEL),
> - STRING_PAIR(IMAGE_SYM_CLASS_UNDEFINED_LABEL),
> - STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT),
> - STRING_PAIR(IMAGE_SYM_CLASS_ARGUMENT),
> - STRING_PAIR(IMAGE_SYM_CLASS_STRUCT_TAG),
> - STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_UNION),
> - STRING_PAIR(IMAGE_SYM_CLASS_UNION_TAG),
> - STRING_PAIR(IMAGE_SYM_CLASS_TYPE_DEFINITION),
> - STRING_PAIR(IMAGE_SYM_CLASS_UNDEFINED_STATIC),
> - STRING_PAIR(IMAGE_SYM_CLASS_ENUM_TAG),
> - STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_ENUM),
> - STRING_PAIR(IMAGE_SYM_CLASS_REGISTER_PARAM),
> - STRING_PAIR(IMAGE_SYM_CLASS_BIT_FIELD),
> - STRING_PAIR(IMAGE_SYM_CLASS_BLOCK),
> - STRING_PAIR(IMAGE_SYM_CLASS_FUNCTION),
> - STRING_PAIR(IMAGE_SYM_CLASS_END_OF_STRUCT),
> - STRING_PAIR(IMAGE_SYM_CLASS_FILE),
> - STRING_PAIR(IMAGE_SYM_CLASS_SECTION),
> - STRING_PAIR(IMAGE_SYM_CLASS_WEAK_EXTERNAL),
> - STRING_PAIR(IMAGE_SYM_CLASS_CLR_TOKEN),
> -};
> +namespace {
>
> -static const pod_pair<COFF::RelocationTypeX86, const char *>
> -RelocationTypeX86Pairs [] = {
> - STRING_PAIR(IMAGE_REL_I386_ABSOLUTE),
> - STRING_PAIR(IMAGE_REL_I386_DIR16),
> - STRING_PAIR(IMAGE_REL_I386_REL16),
> - STRING_PAIR(IMAGE_REL_I386_DIR32),
> - STRING_PAIR(IMAGE_REL_I386_DIR32NB),
> - STRING_PAIR(IMAGE_REL_I386_SEG12),
> - STRING_PAIR(IMAGE_REL_I386_SECTION),
> - STRING_PAIR(IMAGE_REL_I386_SECREL),
> - STRING_PAIR(IMAGE_REL_I386_TOKEN),
> - STRING_PAIR(IMAGE_REL_I386_SECREL7),
> - STRING_PAIR(IMAGE_REL_I386_REL32),
> - STRING_PAIR(IMAGE_REL_AMD64_ABSOLUTE),
> - STRING_PAIR(IMAGE_REL_AMD64_ADDR64),
> - STRING_PAIR(IMAGE_REL_AMD64_ADDR32),
> - STRING_PAIR(IMAGE_REL_AMD64_ADDR32NB),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32_1),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32_2),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32_3),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32_4),
> - STRING_PAIR(IMAGE_REL_AMD64_REL32_5),
> - STRING_PAIR(IMAGE_REL_AMD64_SECTION),
> - STRING_PAIR(IMAGE_REL_AMD64_SECREL),
> - STRING_PAIR(IMAGE_REL_AMD64_SECREL7),
> - STRING_PAIR(IMAGE_REL_AMD64_TOKEN),
> - STRING_PAIR(IMAGE_REL_AMD64_SREL32),
> - STRING_PAIR(IMAGE_REL_AMD64_PAIR),
> - STRING_PAIR(IMAGE_REL_AMD64_SSPAN32)
> -};
> +class COFFDumper {
> + const object::COFFObjectFile &Obj;
> + COFFYAML::Object YAMLObj;
> + void dumpHeader(const object::coff_file_header *Header);
> + void dumpSections(unsigned numSections);
> + void dumpSymbols(unsigned numSymbols);
> + StringRef getHexString(ArrayRef<uint8_t> Data);
> + std::vector<std::string> Strings;
>
> -static const pod_pair<COFF::RelocationTypesARM, const char *>
> -RelocationTypesARMPairs [] = {
> - STRING_PAIR(IMAGE_REL_ARM_ABSOLUTE),
> - STRING_PAIR(IMAGE_REL_ARM_ADDR32),
> - STRING_PAIR(IMAGE_REL_ARM_ADDR32NB),
> - STRING_PAIR(IMAGE_REL_ARM_BRANCH24),
> - STRING_PAIR(IMAGE_REL_ARM_BRANCH11),
> - STRING_PAIR(IMAGE_REL_ARM_TOKEN),
> - STRING_PAIR(IMAGE_REL_ARM_BLX24),
> - STRING_PAIR(IMAGE_REL_ARM_BLX11),
> - STRING_PAIR(IMAGE_REL_ARM_SECTION),
> - STRING_PAIR(IMAGE_REL_ARM_SECREL),
> - STRING_PAIR(IMAGE_REL_ARM_MOV32A),
> - STRING_PAIR(IMAGE_REL_ARM_MOV32T),
> - STRING_PAIR(IMAGE_REL_ARM_BRANCH20T),
> - STRING_PAIR(IMAGE_REL_ARM_BRANCH24T),
> - STRING_PAIR(IMAGE_REL_ARM_BLX23T)
> +public:
> + COFFDumper(const object::COFFObjectFile &Obj);
> + COFFYAML::Object &getYAMLObj();
> };
> -#undef STRING_PAIR
>
> -static raw_ostream &writeName(raw_ostream &Out,
> - const char *Name, std::size_t NameSize) {
> - for (std::size_t i = 0; i < NameSize; ++i) {
> - if (!Name[i]) break;
> - Out << Name[i];
> - }
> - return Out;
> }
>
> -// Given an array of pod_pair<enum, const char *>, write all enums that
> match
> -template <typename T, std::size_t N>
> -static raw_ostream &writeBitMask(raw_ostream &Out,
> - const pod_pair<T, const char *> (&Arr)[N],
> - unsigned long Val) {
> - for (std::size_t i = 0; i < N; ++i)
> - if (Val & Arr[i].first)
> - Out << Arr[i].second << ", ";
> - return Out;
> +static void check(error_code ec) {
> + if (ec)
> + report_fatal_error(ec.message());
> }
>
> -// Given an array of pod_pair<enum, const char *>, look up a value
> -template <typename T, std::size_t N>
> -const char *nameLookup(const pod_pair<T, const char *> (&Arr)[N],
> - unsigned long Val, const char *NotFound = NULL) {
> - T n = static_cast<T>(Val);
> - for (std::size_t i = 0; i < N; ++i)
> - if (n == Arr[i].first)
> - return Arr[i].second;
> - return NotFound;
> +COFFDumper::COFFDumper(const object::COFFObjectFile &Obj) : Obj(Obj) {
> + const object::coff_file_header *Header;
> + check(Obj.getHeader(Header));
> + dumpHeader(Header);
> + dumpSections(Header->NumberOfSections);
> + dumpSymbols(Header->NumberOfSymbols);
> }
>
> -static void yamlCOFFHeader(const object::coff_file_header *Header,
> - raw_ostream &Out) {
> - Out << "header: !Header\n";
> - Out << " Machine: ";
> - Out << nameLookup(MachineTypePairs, Header->Machine, "#
> Unknown_MachineTypes")
> - << " # (";
> - objyaml::writeHexNumber(Out, Header->Machine) << ")\n\n";
> +void COFFDumper::dumpHeader(const object::coff_file_header *Header) {
> + YAMLObj.Header.Machine = Header->Machine;
> + YAMLObj.Header.Characteristics = Header->Characteristics;
> }
>
> -
> -static void yamlCOFFSections(object::COFFObjectFile &Obj,
> - std::size_t NumSections, raw_ostream &Out) {
> +void COFFDumper::dumpSections(unsigned NumSections) {
> + std::vector<COFFYAML::Section> &Sections = YAMLObj.Sections;
> error_code ec;
> - Out << "sections:\n";
> for (object::section_iterator iter = Obj.begin_sections();
> iter != Obj.end_sections(); iter.increment(ec)) {
> - const object::coff_section *sect = Obj.getCOFFSection(iter);
> -
> - Out << " - !Section\n";
> - Out << " Name: ";
> - writeName(Out, sect->Name, sizeof(sect->Name)) << '\n';
> -
> - Out << " Characteristics: [";
> - writeBitMask(Out, SectionCharacteristicsPairs1, sect->Characteristics);
> - Out << nameLookup(SectionCharacteristicsPairsAlignment,
> - sect->Characteristics & 0x00F00000, "#
> Unrecognized_IMAGE_SCN_ALIGN")
> - << ", ";
> - writeBitMask(Out, SectionCharacteristicsPairs2, sect->Characteristics);
> - Out << "] # ";
> - objyaml::writeHexNumber(Out, sect->Characteristics) << '\n';
> + check(ec);
> + const object::coff_section *Sect = Obj.getCOFFSection(iter);
> + COFFYAML::Section Sec;
> + Sec.Name = Sect->Name; // FIXME: check the null termination!
> + uint32_t Characteristics = Sect->Characteristics;
> + Sec.Header.Characteristics = Characteristics;
> + Sec.Alignment = 1 << (((Characteristics >> 20) & 0xf) - 1);
>
> ArrayRef<uint8_t> sectionData;
> - Obj.getSectionContents(sect, sectionData);
> - Out << " SectionData: ";
> - objyaml::writeHexStream(Out, sectionData) << '\n';
> - if (iter->begin_relocations() != iter->end_relocations())
> - Out << " Relocations:\n";
> + Obj.getSectionContents(Sect, sectionData);
> + Sec.SectionData = getHexString(sectionData);
> +
> + std::vector<COFF::relocation> Relocations;
> for (object::relocation_iterator rIter = iter->begin_relocations();
> rIter != iter->end_relocations();
> rIter.increment(ec)) {
> const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
> -
> - Out << " - !Relocation\n";
> - Out << " VirtualAddress: " ;
> - objyaml::writeHexNumber(Out, reloc->VirtualAddress) << '\n';
> - Out << " SymbolTableIndex: " << reloc->SymbolTableIndex <<
> '\n';
> - Out << " Type: "
> - << nameLookup(RelocationTypeX86Pairs, reloc->Type) << '\n';
> - // TODO: Use the correct reloc type for the machine.
> - Out << '\n';
> - }
> -
> + COFF::relocation Rel;
> + Rel.VirtualAddress = reloc->VirtualAddress;
> + Rel.SymbolTableIndex = reloc->SymbolTableIndex;
> + Rel.Type = reloc->Type;
> + Relocations.push_back(Rel);
> + }
> + Sec.Relocations = Relocations;
> + Sections.push_back(Sec);
> }
> }
>
> -static void yamlCOFFSymbols(object::COFFObjectFile &Obj, std::size_t
> NumSymbols,
> - raw_ostream &Out) {
> +void COFFDumper::dumpSymbols(unsigned NumSymbols) {
> error_code ec;
> - Out << "symbols:\n";
> + std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
> for (object::symbol_iterator iter = Obj.begin_symbols();
> iter != Obj.end_symbols(); iter.increment(ec)) {
> - // Gather all the info that we need
> - StringRef str;
> - const object::coff_symbol *symbol = Obj.getCOFFSymbol(iter);
> - Obj.getSymbolName(symbol, str);
> - std::size_t simpleType = symbol->getBaseType();
> - std::size_t complexType = symbol->getComplexType();
> - std::size_t storageClass = symbol->StorageClass;
> -
> - Out << " - !Symbol\n";
> - Out << " Name: " << str << '\n';
> -
> - Out << " Value: " << symbol->Value << '\n';
> - Out << " SectionNumber: " << symbol->SectionNumber << '\n';
> -
> - Out << " SimpleType: "
> - << nameLookup(SymbolBaseTypePairs, simpleType,
> - "# Unknown_SymbolBaseType")
> - << " # (" << simpleType << ")\n";
> -
> - Out << " ComplexType: "
> - << nameLookup(SymbolComplexTypePairs, complexType,
> - "# Unknown_SymbolComplexType")
> - << " # (" << complexType << ")\n";
> -
> - Out << " StorageClass: "
> - << nameLookup(SymbolStorageClassPairs, storageClass,
> - "# Unknown_StorageClass")
> - << " # (" << (int) storageClass << ")\n";
> -
> - if (symbol->NumberOfAuxSymbols > 0) {
> - ArrayRef<uint8_t> aux = Obj.getSymbolAuxData(symbol);
> - Out << " NumberOfAuxSymbols: "
> - << (int) symbol->NumberOfAuxSymbols << '\n';
> - Out << " AuxillaryData: ";
> - objyaml::writeHexStream(Out, aux);
> - }
> + check(ec);
> + const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
> + COFFYAML::Symbol Sym;
> + Obj.getSymbolName(Symbol, Sym.Name);
> + Sym.SimpleType = COFF::SymbolBaseType(Symbol->getBaseType());
> + Sym.ComplexType = COFF::SymbolComplexType(Symbol->getComplexType());
> + Sym.Header.StorageClass = Symbol->StorageClass;
> + Sym.Header.Value = Symbol->Value;
> + Sym.Header.SectionNumber = Symbol->SectionNumber;
> + Sym.Header.NumberOfAuxSymbols = Symbol->NumberOfAuxSymbols;
> + Sym.AuxiliaryData = getHexString(Obj.getSymbolAuxData(Symbol));
> + Symbols.push_back(Sym);
> + }
> +}
>
> - Out << '\n';
> +StringRef COFFDumper::getHexString(ArrayRef<uint8_t> Data) {
> + std::string S;
> + for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I !=
> E;
> + ++I) {
> + uint8_t Byte = *I;
> + S.push_back(hexdigit(Byte >> 4));
> + S.push_back(hexdigit(Byte & 0xf));
> }
> + Strings.push_back(S);
> + return Strings.back();
> }
>
> +COFFYAML::Object &COFFDumper::getYAMLObj() {
> + return YAMLObj;
> +}
>
> -error_code coff2yaml(raw_ostream &Out, MemoryBuffer *TheObj) {
> +error_code coff2yaml(raw_ostream &Out, MemoryBuffer *Buff) {
> error_code ec;
> - object::COFFObjectFile obj(TheObj, ec);
> - if (ec)
> - return ec;
> -
> - const object::coff_file_header *hd;
> - ec = obj.getHeader(hd);
> - if (ec)
> - return ec;
> + object::COFFObjectFile Obj(Buff, ec);
> + check(ec);
> + COFFDumper Dumper(Obj);
>
> - yamlCOFFHeader(hd, Out);
> - yamlCOFFSections(obj, hd->NumberOfSections, Out);
> - yamlCOFFSymbols(obj, hd->NumberOfSymbols, Out);
> + yaml::Output Yout(Out);
> + Yout << Dumper.getYAMLObj();
>
> - return ec;
> + return object::object_error::success;
> }
>
> Modified: llvm/trunk/tools/yaml2obj/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/CMakeLists.txt?rev=182169&r1=182168&r2=182169&view=diff
> ==============================================================================
> --- llvm/trunk/tools/yaml2obj/CMakeLists.txt (original)
> +++ llvm/trunk/tools/yaml2obj/CMakeLists.txt Fri May 17 17:58:42 2013
> @@ -1,3 +1,5 @@
> +set(LLVM_LINK_COMPONENTS object)
> +
> add_llvm_utility(yaml2obj
> yaml2obj.cpp
> )
>
> Modified: llvm/trunk/tools/yaml2obj/yaml2obj.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.cpp?rev=182169&r1=182168&r2=182169&view=diff
> ==============================================================================
> --- llvm/trunk/tools/yaml2obj/yaml2obj.cpp (original)
> +++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp Fri May 17 17:58:42 2013
> @@ -18,7 +18,7 @@
> #include "llvm/ADT/StringExtras.h"
> #include "llvm/ADT/StringMap.h"
> #include "llvm/ADT/StringSwitch.h"
> -#include "llvm/Support/COFF.h"
> +#include "llvm/Object/COFFYaml.h"
> #include "llvm/Support/Casting.h"
> #include "llvm/Support/CommandLine.h"
> #include "llvm/Support/Endian.h"
> @@ -27,7 +27,6 @@
> #include "llvm/Support/PrettyStackTrace.h"
> #include "llvm/Support/Signals.h"
> #include "llvm/Support/SourceMgr.h"
> -#include "llvm/Support/YAMLTraits.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/Support/system_error.h"
> #include <vector>
> @@ -37,41 +36,6 @@ using namespace llvm;
> static cl::opt<std::string>
> Input(cl::Positional, cl::desc("<input>"), cl::init("-"));
>
> -// The structure of the yaml files is not an exact 1:1 match to COFF. In
> order
> -// to use yaml::IO, we use these structures which are closer to the source.
> -namespace COFFYAML {
> - struct Section {
> - COFF::section Header;
> - unsigned Alignment;
> - StringRef SectionData;
> - std::vector<COFF::relocation> Relocations;
> - StringRef Name;
> - Section() {
> - memset(&Header, 0, sizeof(COFF::section));
> - }
> - };
> -
> - struct Symbol {
> - COFF::symbol Header;
> - COFF::SymbolBaseType SimpleType;
> - COFF::SymbolComplexType ComplexType;
> - StringRef AuxiliaryData;
> - StringRef Name;
> - Symbol() {
> - memset(&Header, 0, sizeof(COFF::symbol));
> - }
> - };
> -
> - struct Object {
> - COFF::header Header;
> - std::vector<Section> Sections;
> - std::vector<Symbol> Symbols;
> - Object() {
> - memset(&Header, 0, sizeof(COFF::header));
> - }
> - };
> -}
> -
> /// This parses a yaml stream that represents a COFF object file.
> /// See docs/yaml2obj for the yaml scheema.
> struct COFFParser {
> @@ -322,329 +286,6 @@ bool writeCOFF(COFFParser &CP, raw_ostre
> return true;
> }
>
> -LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
> -LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
> -LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
> -
> -namespace llvm {
> -
> -namespace COFF {
> - Characteristics operator|(Characteristics a, Characteristics b) {
> - uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
> - return static_cast<Characteristics>(Ret);
> - }
> -
> - SectionCharacteristics
> - operator|(SectionCharacteristics a, SectionCharacteristics b) {
> - uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
> - return static_cast<SectionCharacteristics>(Ret);
> - }
> -}
> -
> -namespace yaml {
> -
> -#define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
> -
> -template <>
> -struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
> - static void bitset(IO &IO, COFF::SectionCharacteristics &Value) {
> - BCase(IMAGE_SCN_TYPE_NO_PAD);
> - BCase(IMAGE_SCN_CNT_CODE);
> - BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
> - BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
> - BCase(IMAGE_SCN_LNK_OTHER);
> - BCase(IMAGE_SCN_LNK_INFO);
> - BCase(IMAGE_SCN_LNK_REMOVE);
> - BCase(IMAGE_SCN_LNK_COMDAT);
> - BCase(IMAGE_SCN_GPREL);
> - BCase(IMAGE_SCN_MEM_PURGEABLE);
> - BCase(IMAGE_SCN_MEM_16BIT);
> - BCase(IMAGE_SCN_MEM_LOCKED);
> - BCase(IMAGE_SCN_MEM_PRELOAD);
> - BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
> - BCase(IMAGE_SCN_MEM_DISCARDABLE);
> - BCase(IMAGE_SCN_MEM_NOT_CACHED);
> - BCase(IMAGE_SCN_MEM_NOT_PAGED);
> - BCase(IMAGE_SCN_MEM_SHARED);
> - BCase(IMAGE_SCN_MEM_EXECUTE);
> - BCase(IMAGE_SCN_MEM_READ);
> - BCase(IMAGE_SCN_MEM_WRITE);
> - }
> -};
> -
> -template <>
> -struct ScalarBitSetTraits<COFF::Characteristics> {
> - static void bitset(IO &IO, COFF::Characteristics &Value) {
> - BCase(IMAGE_FILE_RELOCS_STRIPPED);
> - BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
> - BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
> - BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
> - BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
> - BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
> - BCase(IMAGE_FILE_BYTES_REVERSED_LO);
> - BCase(IMAGE_FILE_32BIT_MACHINE);
> - BCase(IMAGE_FILE_DEBUG_STRIPPED);
> - BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
> - BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
> - BCase(IMAGE_FILE_SYSTEM);
> - BCase(IMAGE_FILE_DLL);
> - BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
> - BCase(IMAGE_FILE_BYTES_REVERSED_HI);
> - }
> -};
> -#undef BCase
> -
> -#define ECase(X) IO.enumCase(Value, #X, COFF::X);
> -
> -template <>
> -struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
> - static void enumeration(IO &IO, COFF::SymbolComplexType &Value) {
> - ECase(IMAGE_SYM_DTYPE_NULL);
> - ECase(IMAGE_SYM_DTYPE_POINTER);
> - ECase(IMAGE_SYM_DTYPE_FUNCTION);
> - ECase(IMAGE_SYM_DTYPE_ARRAY);
> - }
> -};
> -
> -template <>
> -struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
> - static void enumeration(IO &IO, COFF::SymbolStorageClass &Value) {
> - ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
> - ECase(IMAGE_SYM_CLASS_NULL);
> - ECase(IMAGE_SYM_CLASS_AUTOMATIC);
> - ECase(IMAGE_SYM_CLASS_EXTERNAL);
> - ECase(IMAGE_SYM_CLASS_STATIC);
> - ECase(IMAGE_SYM_CLASS_REGISTER);
> - ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
> - ECase(IMAGE_SYM_CLASS_LABEL);
> - ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
> - ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
> - ECase(IMAGE_SYM_CLASS_ARGUMENT);
> - ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
> - ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
> - ECase(IMAGE_SYM_CLASS_UNION_TAG);
> - ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
> - ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
> - ECase(IMAGE_SYM_CLASS_ENUM_TAG);
> - ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
> - ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
> - ECase(IMAGE_SYM_CLASS_BIT_FIELD);
> - ECase(IMAGE_SYM_CLASS_BLOCK);
> - ECase(IMAGE_SYM_CLASS_FUNCTION);
> - ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
> - ECase(IMAGE_SYM_CLASS_FILE);
> - ECase(IMAGE_SYM_CLASS_SECTION);
> - ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
> - ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
> - }
> -};
> -
> -template <>
> -struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
> - static void enumeration(IO &IO, COFF::SymbolBaseType &Value) {
> - ECase(IMAGE_SYM_TYPE_NULL);
> - ECase(IMAGE_SYM_TYPE_VOID);
> - ECase(IMAGE_SYM_TYPE_CHAR);
> - ECase(IMAGE_SYM_TYPE_SHORT);
> - ECase(IMAGE_SYM_TYPE_INT);
> - ECase(IMAGE_SYM_TYPE_LONG);
> - ECase(IMAGE_SYM_TYPE_FLOAT);
> - ECase(IMAGE_SYM_TYPE_DOUBLE);
> - ECase(IMAGE_SYM_TYPE_STRUCT);
> - ECase(IMAGE_SYM_TYPE_UNION);
> - ECase(IMAGE_SYM_TYPE_ENUM);
> - ECase(IMAGE_SYM_TYPE_MOE);
> - ECase(IMAGE_SYM_TYPE_BYTE);
> - ECase(IMAGE_SYM_TYPE_WORD);
> - ECase(IMAGE_SYM_TYPE_UINT);
> - ECase(IMAGE_SYM_TYPE_DWORD);
> - }
> -};
> -
> -template <>
> -struct ScalarEnumerationTraits<COFF::MachineTypes> {
> - static void enumeration(IO &IO, COFF::MachineTypes &Value) {
> - ECase(IMAGE_FILE_MACHINE_UNKNOWN);
> - ECase(IMAGE_FILE_MACHINE_AM33);
> - ECase(IMAGE_FILE_MACHINE_AMD64);
> - ECase(IMAGE_FILE_MACHINE_ARM);
> - ECase(IMAGE_FILE_MACHINE_ARMV7);
> - ECase(IMAGE_FILE_MACHINE_EBC);
> - ECase(IMAGE_FILE_MACHINE_I386);
> - ECase(IMAGE_FILE_MACHINE_IA64);
> - ECase(IMAGE_FILE_MACHINE_M32R);
> - ECase(IMAGE_FILE_MACHINE_MIPS16);
> - ECase(IMAGE_FILE_MACHINE_MIPSFPU);
> - ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
> - ECase(IMAGE_FILE_MACHINE_POWERPC);
> - ECase(IMAGE_FILE_MACHINE_POWERPCFP);
> - ECase(IMAGE_FILE_MACHINE_R4000);
> - ECase(IMAGE_FILE_MACHINE_SH3);
> - ECase(IMAGE_FILE_MACHINE_SH3DSP);
> - ECase(IMAGE_FILE_MACHINE_SH4);
> - ECase(IMAGE_FILE_MACHINE_SH5);
> - ECase(IMAGE_FILE_MACHINE_THUMB);
> - ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
> - }
> -};
> -
> -template <>
> -struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
> - static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value) {
> - ECase(IMAGE_REL_I386_ABSOLUTE);
> - ECase(IMAGE_REL_I386_DIR16);
> - ECase(IMAGE_REL_I386_REL16);
> - ECase(IMAGE_REL_I386_DIR32);
> - ECase(IMAGE_REL_I386_DIR32NB);
> - ECase(IMAGE_REL_I386_SEG12);
> - ECase(IMAGE_REL_I386_SECTION);
> - ECase(IMAGE_REL_I386_SECREL);
> - ECase(IMAGE_REL_I386_TOKEN);
> - ECase(IMAGE_REL_I386_SECREL7);
> - ECase(IMAGE_REL_I386_REL32);
> - ECase(IMAGE_REL_AMD64_ABSOLUTE);
> - ECase(IMAGE_REL_AMD64_ADDR64);
> - ECase(IMAGE_REL_AMD64_ADDR32);
> - ECase(IMAGE_REL_AMD64_ADDR32NB);
> - ECase(IMAGE_REL_AMD64_REL32);
> - ECase(IMAGE_REL_AMD64_REL32_1);
> - ECase(IMAGE_REL_AMD64_REL32_2);
> - ECase(IMAGE_REL_AMD64_REL32_3);
> - ECase(IMAGE_REL_AMD64_REL32_4);
> - ECase(IMAGE_REL_AMD64_REL32_5);
> - ECase(IMAGE_REL_AMD64_SECTION);
> - ECase(IMAGE_REL_AMD64_SECREL);
> - ECase(IMAGE_REL_AMD64_SECREL7);
> - ECase(IMAGE_REL_AMD64_TOKEN);
> - ECase(IMAGE_REL_AMD64_SREL32);
> - ECase(IMAGE_REL_AMD64_PAIR);
> - ECase(IMAGE_REL_AMD64_SSPAN32);
> - }
> -};
> -
> -#undef ECase
> -
> -template <>
> -struct MappingTraits<COFFYAML::Symbol> {
> - struct NStorageClass {
> - NStorageClass(IO&) : StorageClass(COFF::SymbolStorageClass(0)) {
> - }
> - NStorageClass(IO&, uint8_t S) :
> StorageClass(COFF::SymbolStorageClass(S)) {
> - }
> - uint8_t denormalize(IO &) {
> - return StorageClass;
> - }
> -
> - COFF::SymbolStorageClass StorageClass;
> - };
> -
> - static void mapping(IO &IO, COFFYAML::Symbol &S) {
> - MappingNormalization<NStorageClass, uint8_t> NS(IO,
> S.Header.StorageClass);
> -
> - IO.mapRequired("SimpleType", S.SimpleType);
> - IO.mapOptional("NumberOfAuxSymbols", S.Header.NumberOfAuxSymbols);
> - IO.mapRequired("Name", S.Name);
> - IO.mapRequired("StorageClass", NS->StorageClass);
> - IO.mapOptional("AuxiliaryData", S.AuxiliaryData);
> - IO.mapRequired("ComplexType", S.ComplexType);
> - IO.mapRequired("Value", S.Header.Value);
> - IO.mapRequired("SectionNumber", S.Header.SectionNumber);
> - }
> -};
> -
> -template <>
> -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 NType {
> - NType(IO &) : Type(COFF::RelocationTypeX86(0)) {
> - }
> - 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<NType, uint16_t> NT(IO, Rel.Type);
> -
> - IO.mapRequired("Type", NT->Type);
> - IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
> - IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
> - }
> -};
> -
> -template <>
> -struct MappingTraits<COFFYAML::Section> {
> - struct NCharacteristics {
> - NCharacteristics(IO &) :
> Characteristics(COFF::SectionCharacteristics(0)) {
> - }
> - NCharacteristics(IO &, uint32_t C) :
> - Characteristics(COFF::SectionCharacteristics(C)) {
> - }
> - uint32_t denormalize(IO &) {
> - return Characteristics;
> - }
> - COFF::SectionCharacteristics Characteristics;
> - };
> -
> - static void mapping(IO &IO, COFFYAML::Section &Sec) {
> - MappingNormalization<NCharacteristics, uint32_t> NC(IO,
> -
> Sec.Header.Characteristics);
> - IO.mapOptional("Relocations", Sec.Relocations);
> - IO.mapRequired("SectionData", Sec.SectionData);
> - IO.mapRequired("Characteristics", NC->Characteristics);
> - IO.mapRequired("Name", Sec.Name);
> - IO.mapOptional("Alignment", Sec.Alignment);
> - }
> -};
> -
> -template <>
> -struct MappingTraits<COFFYAML::Object> {
> - static void mapping(IO &IO, COFFYAML::Object &Obj) {
> - IO.mapRequired("sections", Obj.Sections);
> - IO.mapRequired("header", Obj.Header);
> - IO.mapRequired("symbols", Obj.Symbols);
> - }
> -};
> -} // end namespace yaml
> -} // end namespace llvm
> -
> int main(int argc, char **argv) {
> cl::ParseCommandLineOptions(argc, argv);
> sys::PrintStackTraceOnErrorSignal();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
More information about the llvm-commits
mailing list