Index: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h =================================================================== --- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h +++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h @@ -129,12 +129,6 @@ std::vector Slices; }; -struct MachFile { - bool isFat; - UniversalBinary FatFile; - Object ThinFile; -}; - } // namespace llvm::MachOYAML } // namespace llvm @@ -174,10 +168,6 @@ static void mapping(IO &IO, MachOYAML::UniversalBinary &UniversalBinary); }; -template <> struct MappingTraits { - static void mapping(IO &IO, MachOYAML::MachFile &MachFile); -}; - template <> struct MappingTraits { static void mapping(IO &IO, MachOYAML::LoadCommand &LoadCommand); }; Index: llvm/trunk/include/llvm/ObjectYAML/ObjectYAML.h =================================================================== --- llvm/trunk/include/llvm/ObjectYAML/ObjectYAML.h +++ llvm/trunk/include/llvm/ObjectYAML/ObjectYAML.h @@ -0,0 +1,35 @@ +//===- ObjectYAML.h ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_OBJECTYAML_H +#define LLVM_OBJECTYAML_OBJECTYAML_H + +#include "llvm/Support/YAMLTraits.h" +#include "llvm/ObjectYAML/ELFYAML.h" +#include "llvm/ObjectYAML/COFFYAML.h" +#include "llvm/ObjectYAML/MachOYAML.h" + +namespace llvm { +namespace yaml { + +struct YamlObjectFile { + std::unique_ptr Elf; + std::unique_ptr Coff; + std::unique_ptr MachO; + std::unique_ptr FatMachO; +}; + +template <> struct MappingTraits { + static void mapping(IO &IO, YamlObjectFile &ObjectFile); +}; + +} // namespace yaml +} // namespace llvm + +#endif Index: llvm/trunk/lib/ObjectYAML/CMakeLists.txt =================================================================== --- llvm/trunk/lib/ObjectYAML/CMakeLists.txt +++ llvm/trunk/lib/ObjectYAML/CMakeLists.txt @@ -3,4 +3,5 @@ COFFYAML.cpp ELFYAML.cpp MachOYAML.cpp + ObjectYAML.cpp ) Index: llvm/trunk/lib/ObjectYAML/COFFYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/COFFYAML.cpp +++ llvm/trunk/lib/ObjectYAML/COFFYAML.cpp @@ -493,6 +493,7 @@ } void MappingTraits::mapping(IO &IO, COFFYAML::Object &Obj) { + IO.mapTag("!COFF", true); IO.mapOptional("OptionalHeader", Obj.OptionalHeader); IO.mapRequired("header", Obj.Header); IO.mapRequired("sections", Obj.Sections); Index: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp +++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp @@ -820,6 +820,7 @@ void MappingTraits::mapping(IO &IO, ELFYAML::Object &Object) { assert(!IO.getContext() && "The IO context is initialized already"); IO.setContext(&Object); + IO.mapTag("!ELF", true); IO.mapRequired("FileHeader", Object.Header); IO.mapOptional("Sections", Object.Sections); IO.mapOptional("Symbols", Object.Symbols); Index: llvm/trunk/lib/ObjectYAML/MachOYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/MachOYAML.cpp +++ llvm/trunk/lib/ObjectYAML/MachOYAML.cpp @@ -132,34 +132,6 @@ IO.setContext(nullptr); } -void MappingTraits::mapping( - IO &IO, MachOYAML::MachFile &MachFile) { - if (!IO.getContext()) { - IO.setContext(&MachFile); - } - if (IO.outputting()) { - if (MachFile.isFat) { - IO.mapTag("!fat-mach-o", true); - MappingTraits::mapping(IO, MachFile.FatFile); - } else { - IO.mapTag("!mach-o", true); - MappingTraits::mapping(IO, MachFile.ThinFile); - } - } else { - if (IO.mapTag("!fat-mach-o")) { - MachFile.isFat = true; - MappingTraits::mapping(IO, MachFile.FatFile); - } else if (IO.mapTag("!mach-o")) { - MachFile.isFat = false; - MappingTraits::mapping(IO, MachFile.ThinFile); - } else { - assert(false && "No tag found in YAML, cannot identify file type!"); - } - } - if (IO.getContext() == &MachFile) - IO.setContext(nullptr); -} - void MappingTraits::mapping( IO &IO, MachOYAML::LinkEditData &LinkEditData) { IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes); Index: llvm/trunk/lib/ObjectYAML/ObjectYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/ObjectYAML.cpp +++ llvm/trunk/lib/ObjectYAML/ObjectYAML.cpp @@ -0,0 +1,57 @@ +//===- ObjectYAML.cpp - YAML utilities for object files -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines a wrapper class for handling tagged YAML input +// +//===----------------------------------------------------------------------===// + +#include "llvm/ObjectYAML/YAML.h" +#include "llvm/ObjectYAML/ObjectYAML.h" + +using namespace llvm; +using namespace yaml; + +void MappingTraits::mapping(IO &IO, + YamlObjectFile &ObjectFile) { + if (IO.outputting()) { + if (ObjectFile.Elf) + MappingTraits::mapping(IO, *ObjectFile.Elf); + if (ObjectFile.Coff) + MappingTraits::mapping(IO, *ObjectFile.Coff); + if (ObjectFile.MachO) + MappingTraits::mapping(IO, *ObjectFile.MachO); + if (ObjectFile.FatMachO) + MappingTraits::mapping(IO, + *ObjectFile.FatMachO); + } else { + if (IO.mapTag("!ELF")) { + ObjectFile.Elf.reset(new ELFYAML::Object()); + MappingTraits::mapping(IO, *ObjectFile.Elf); + } else if (IO.mapTag("!COFF")) { + ObjectFile.Coff.reset(new COFFYAML::Object()); + MappingTraits::mapping(IO, *ObjectFile.Coff); + } else if (IO.mapTag("!mach-o")) { + ObjectFile.MachO.reset(new MachOYAML::Object()); + MappingTraits::mapping(IO, *ObjectFile.MachO); + } else if (IO.mapTag("!fat-mach-o")) { + ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary()); + MappingTraits::mapping(IO, + *ObjectFile.FatMachO); + } else { + Input &In = (Input &)IO; + std::string Tag = In.getCurrentNode()->getRawTag(); + if (Tag.empty()) + IO.setError("YAML Object File missing document type tag!"); + else + IO.setError( + llvm::Twine("YAML Object File unsupported document type tag '") + + llvm::Twine(Tag.c_str()) + llvm::Twine("'!")); + } + } +} Index: llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml =================================================================== --- llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml +++ llvm/trunk/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: obj2yaml %t | FileCheck %s # CHECK: - Name: .rela.text @@ -14,6 +14,7 @@ # CHECK-NEXT: Symbol: main # CHECK-NEXT: Type: R_AARCH64_TLSGD_ADR_PREL21 +!ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/AMDGPU/elf-definitios.yaml =================================================================== --- llvm/trunk/test/Object/AMDGPU/elf-definitios.yaml +++ llvm/trunk/test/Object/AMDGPU/elf-definitios.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t.o +# RUN: yaml2obj %s > %t.o # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s # CHECK: Format: ELF64-amdgpu-hsacobj @@ -14,7 +14,7 @@ # CHECK: SHF_AMDGPU_HSA_READONLY (0x200000) # CHECK: } ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/AMDGPU/elf32-unknown.yaml =================================================================== --- llvm/trunk/test/Object/AMDGPU/elf32-unknown.yaml +++ llvm/trunk/test/Object/AMDGPU/elf32-unknown.yaml @@ -1,9 +1,9 @@ -# RUN: yaml2obj -format=elf %s > %t.o +# RUN: yaml2obj %s > %t.o # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s # CHECK: Format: ELF32-amdgpu ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/AMDGPU/elf64-relocs.yaml =================================================================== --- llvm/trunk/test/Object/AMDGPU/elf64-relocs.yaml +++ llvm/trunk/test/Object/AMDGPU/elf64-relocs.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -r %t | FileCheck %s # CHECK: Relocations [ @@ -13,6 +13,7 @@ # CHECK: } # CHECK: ] +!ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/AMDGPU/elf64-unknown.yaml =================================================================== --- llvm/trunk/test/Object/AMDGPU/elf64-unknown.yaml +++ llvm/trunk/test/Object/AMDGPU/elf64-unknown.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t.o +# RUN: yaml2obj %s > %t.o # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s # CHECK: Format: ELF64-amdgpu Index: llvm/trunk/test/Object/Inputs/COFF/i386.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/i386.yaml +++ llvm/trunk/test/Object/Inputs/COFF/i386.yaml @@ -1,3 +1,4 @@ +!COFF header: !Header Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/Object/Inputs/COFF/long-file-symbol.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/long-file-symbol.yaml +++ llvm/trunk/test/Object/Inputs/COFF/long-file-symbol.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_AMD64 Characteristics: [ IMAGE_FILE_RELOCS_STRIPPED, IMAGE_FILE_LINE_NUMS_STRIPPED ] Index: llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml +++ llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_I386 Characteristics: [ IMAGE_FILE_RELOCS_STRIPPED, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE ] Index: llvm/trunk/test/Object/Inputs/COFF/section-aux-symbol.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/section-aux-symbol.yaml +++ llvm/trunk/test/Object/Inputs/COFF/section-aux-symbol.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_I386 Characteristics: [ IMAGE_FILE_RELOCS_STRIPPED, IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE, IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/Object/Inputs/COFF/weak-external.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/weak-external.yaml +++ llvm/trunk/test/Object/Inputs/COFF/weak-external.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_I386 Characteristics: [ IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE ] Index: llvm/trunk/test/Object/Inputs/COFF/weak-externals.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/weak-externals.yaml +++ llvm/trunk/test/Object/Inputs/COFF/weak-externals.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_ARMNT Characteristics: [ ] Index: llvm/trunk/test/Object/Inputs/COFF/x86-64.yaml =================================================================== --- llvm/trunk/test/Object/Inputs/COFF/x86-64.yaml +++ llvm/trunk/test/Object/Inputs/COFF/x86-64.yaml @@ -1,3 +1,4 @@ +!COFF header: !Header Machine: IMAGE_FILE_MACHINE_AMD64 # (0x8664) Index: llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml =================================================================== --- llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml +++ llvm/trunk/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -r %t | FileCheck %s # CHECK: Relocations [ @@ -13,6 +13,7 @@ # CHECK-NEXT: } # CHECK-NEXT: ] +!ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/Mips/abi-flags.yaml =================================================================== --- llvm/trunk/test/Object/Mips/abi-flags.yaml +++ llvm/trunk/test/Object/Mips/abi-flags.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -mips-abi-flags %t | FileCheck -check-prefix=OBJ %s # RUN: obj2yaml %t | FileCheck -check-prefix=YAML %s @@ -34,6 +34,7 @@ # YAML-NEXT: CPR1Size: REG_64 # YAML-NEXT: Flags1: [ ODDSPREG ] +!ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2MSB Index: llvm/trunk/test/Object/Mips/elf-abi.yaml =================================================================== --- llvm/trunk/test/Object/Mips/elf-abi.yaml +++ llvm/trunk/test/Object/Mips/elf-abi.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf -docnum=1 %s > %t.o32 +# RUN: yaml2obj -docnum=1 %s > %t.o32 # RUN: llvm-readobj -file-headers %t.o32 | FileCheck -check-prefix=O32OBJ %s # RUN: obj2yaml %t.o32 | FileCheck -check-prefix=O32YAML %s @@ -10,7 +10,7 @@ # O32YAML: Flags: [ EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ] -# RUN: yaml2obj -format=elf -docnum=2 %s > %t.o64 +# RUN: yaml2obj -docnum=2 %s > %t.o64 # RUN: llvm-readobj -file-headers %t.o64 | FileCheck -check-prefix=O64OBJ %s # RUN: obj2yaml %t.o64 | FileCheck -check-prefix=O64YAML %s @@ -22,7 +22,7 @@ # O64YAML: Flags: [ EF_MIPS_PIC, EF_MIPS_ABI_O64, EF_MIPS_ARCH_64 ] -# RUN: yaml2obj -format=elf -docnum=3 %s > %t.eabi32 +# RUN: yaml2obj -docnum=3 %s > %t.eabi32 # RUN: llvm-readobj -file-headers %t.eabi32 | FileCheck -check-prefix=E32OBJ %s # RUN: obj2yaml %t.eabi32 | FileCheck -check-prefix=E32YAML %s @@ -34,7 +34,7 @@ # E32YAML: Flags: [ EF_MIPS_PIC, EF_MIPS_ABI_EABI32, EF_MIPS_ARCH_32 ] -# RUN: yaml2obj -format=elf -docnum=4 %s > %t.eabi64 +# RUN: yaml2obj -docnum=4 %s > %t.eabi64 # RUN: llvm-readobj -file-headers %t.eabi64 | FileCheck -check-prefix=E64OBJ %s # RUN: obj2yaml %t.eabi64 | FileCheck -check-prefix=E64YAML %s @@ -47,7 +47,7 @@ # E64YAML: Flags: [ EF_MIPS_PIC, EF_MIPS_ABI_EABI64, EF_MIPS_ARCH_64 ] # o32 ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/Mips/elf-flags.yaml =================================================================== --- llvm/trunk/test/Object/Mips/elf-flags.yaml +++ llvm/trunk/test/Object/Mips/elf-flags.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -file-headers %t | FileCheck -check-prefix=OBJ %s # RUN: obj2yaml %t | FileCheck -check-prefix=YAML %s @@ -25,7 +25,7 @@ # YAML-NEXT: Machine: EM_MIPS # YAML-NEXT: Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI2, EF_MIPS_32BITMODE, EF_MIPS_FP64, EF_MIPS_NAN2008, EF_MIPS_MICROMIPS, EF_MIPS_ARCH_ASE_M16, EF_MIPS_ARCH_ASE_MDMX, EF_MIPS_ABI_O32, EF_MIPS_MACH_OCTEON, EF_MIPS_ARCH_32R6 ] ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/Mips/elf-mips64-rel.yaml =================================================================== --- llvm/trunk/test/Object/Mips/elf-mips64-rel.yaml +++ llvm/trunk/test/Object/Mips/elf-mips64-rel.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -r %t | FileCheck -check-prefix=OBJ %s # RUN: obj2yaml %t | FileCheck -check-prefix=YAML %s @@ -41,7 +41,7 @@ # YAML-NEXT: Type2: R_MIPS_LO16 # YAML-NEXT: SpecSym: RSS_GP0 ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/X86/yaml2obj-elf-x86-rel.yaml =================================================================== --- llvm/trunk/test/Object/X86/yaml2obj-elf-x86-rel.yaml +++ llvm/trunk/test/Object/X86/yaml2obj-elf-x86-rel.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -r %t | FileCheck %s # CHECK: Relocations [ @@ -7,6 +7,7 @@ # CHECK-NEXT: } # CHECK-NEXT: ] +!ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/elf-unknown-type.test =================================================================== --- llvm/trunk/test/Object/elf-unknown-type.test +++ llvm/trunk/test/Object/elf-unknown-type.test @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -file-headers - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -file-headers - | FileCheck %s !ELF FileHeader: !FileHeader Index: llvm/trunk/test/Object/obj2yaml-sectiongroup.test =================================================================== --- llvm/trunk/test/Object/obj2yaml-sectiongroup.test +++ llvm/trunk/test/Object/obj2yaml-sectiongroup.test @@ -1,7 +1,7 @@ # Checks that the tool is able to read section groups with ELF. RUN: obj2yaml %p/Inputs/sectionGroup.elf.x86-64 > %t1.sectiongroup.yaml RUN: FileCheck %s --check-prefix ELF-GROUP < %t1.sectiongroup.yaml -RUN: yaml2obj -format=elf %t1.sectiongroup.yaml -o %t2.o.elf +RUN: yaml2obj %t1.sectiongroup.yaml -o %t2.o.elf RUN: llvm-readobj -sections %t2.o.elf | FileCheck %s -check-prefix=SECTIONS #ELF-GROUP: - Name: .group #ELF-GROUP: Type: SHT_GROUP Index: llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test =================================================================== --- llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test +++ llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test @@ -2,7 +2,7 @@ # CHECK: Section alignment is too large ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_AMD64 Characteristics: [] Index: llvm/trunk/test/Object/yaml2obj-coff-multi-doc.test =================================================================== --- llvm/trunk/test/Object/yaml2obj-coff-multi-doc.test +++ llvm/trunk/test/Object/yaml2obj-coff-multi-doc.test @@ -1,15 +1,15 @@ -# RUN: yaml2obj -format=coff -docnum=1 %s \ +# RUN: yaml2obj -docnum=1 %s \ # RUN: | llvm-readobj -symbols - | FileCheck -check-prefix=DOC1 %s -# RUN: yaml2obj -format=coff -docnum=2 %s \ +# RUN: yaml2obj -docnum=2 %s \ # RUN: | llvm-readobj -symbols - | FileCheck -check-prefix=DOC2 %s -# RUN: not yaml2obj -format=coff -docnum=3 %s 2>&1 \ +# RUN: not yaml2obj -docnum=3 %s 2>&1 \ # RUN: | FileCheck -check-prefix=DOC3 %s # DOC1: Name: _sym1 # DOC2: Name: _sym2 # DOC3: yaml2obj: Cannot find the 3rd document ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_I386 Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] @@ -49,7 +49,7 @@ ComplexType: IMAGE_SYM_DTYPE_NULL StorageClass: IMAGE_SYM_CLASS_EXTERNAL ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_I386 Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml @@ -1,6 +1,6 @@ # Check that yaml2obj takes in account section AddressAlign field. -# RUN: yaml2obj -format=elf %s > %t +# RUN: yaml2obj %s > %t # RUN: llvm-readobj -s %t | FileCheck %s # CHECK: Section { @@ -20,7 +20,7 @@ # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/Object/yaml2obj-elf-bits-endian.test =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-bits-endian.test +++ llvm/trunk/test/Object/yaml2obj-elf-bits-endian.test @@ -1,7 +1,7 @@ -RUN: yaml2obj -format=elf %p/Inputs/ELF/LE64.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix LE64 -RUN: yaml2obj -format=elf %p/Inputs/ELF/BE64.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix BE64 -RUN: yaml2obj -format=elf %p/Inputs/ELF/LE32.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix LE32 -RUN: yaml2obj -format=elf %p/Inputs/ELF/BE32.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix BE32 +RUN: yaml2obj %p/Inputs/ELF/LE64.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix LE64 +RUN: yaml2obj %p/Inputs/ELF/BE64.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix BE64 +RUN: yaml2obj %p/Inputs/ELF/LE32.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix LE32 +RUN: yaml2obj %p/Inputs/ELF/BE32.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix BE32 LE64: Class: 64-bit (0x2) LE64-NEXT: DataEncoding: LittleEndian (0x1) Index: llvm/trunk/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -file-headers - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -file-headers - | FileCheck %s !ELF FileHeader: Class: ELFCLASS32 Index: llvm/trunk/test/Object/yaml2obj-elf-file-headers.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-file-headers.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-file-headers.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -file-headers - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -file-headers - | FileCheck %s !ELF FileHeader: Class: ELFCLASS64 Index: llvm/trunk/test/Object/yaml2obj-elf-multi-doc.test =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-multi-doc.test +++ llvm/trunk/test/Object/yaml2obj-elf-multi-doc.test @@ -1,8 +1,8 @@ -# RUN: yaml2obj -format=elf -docnum=1 %s \ +# RUN: yaml2obj -docnum=1 %s \ # RUN: | llvm-readobj -symbols - | FileCheck -check-prefix=DOC1 %s -# RUN: yaml2obj -format=elf -docnum=2 %s \ +# RUN: yaml2obj -docnum=2 %s \ # RUN: | llvm-readobj -symbols - | FileCheck -check-prefix=DOC2 %s -# RUN: not yaml2obj -format=elf -docnum=3 %s 2>&1 \ +# RUN: not yaml2obj -docnum=3 %s 2>&1 \ # RUN: | FileCheck -check-prefix=DOC3 %s # DOC1: Name: T1 (1) Index: llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -sections -relocations - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -sections -relocations - | FileCheck %s !ELF FileHeader: !FielHeader Index: llvm/trunk/test/Object/yaml2obj-elf-rel.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-rel.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-rel.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -sections -relocations - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -sections -relocations - | FileCheck %s !ELF FileHeader: !FileHeader Index: llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml @@ -1,5 +1,5 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -sections -section-data - | FileCheck %s -# RUN: yaml2obj -format=elf -o %t %s +# RUN: yaml2obj %s | llvm-readobj -sections -section-data - | FileCheck %s +# RUN: yaml2obj -o %t %s # RUN: llvm-readobj -sections -section-data %t | FileCheck %s !ELF Index: llvm/trunk/test/Object/yaml2obj-elf-section-invalid-size.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-section-invalid-size.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-section-invalid-size.yaml @@ -1,4 +1,4 @@ -# RUN: not yaml2obj -format=elf -o %t %s 2>&1 | FileCheck %s +# RUN: not yaml2obj -o %t %s 2>&1 | FileCheck %s !ELF FileHeader: Index: llvm/trunk/test/Object/yaml2obj-elf-symbol-LocalGlobalWeak.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-symbol-LocalGlobalWeak.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-symbol-LocalGlobalWeak.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -symbols - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -symbols - | FileCheck %s !ELF FileHeader: Class: ELFCLASS64 Index: llvm/trunk/test/Object/yaml2obj-elf-symbol-basic.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-symbol-basic.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-symbol-basic.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -symbols - | FileCheck %s +# RUN: yaml2obj %s | llvm-readobj -symbols - | FileCheck %s !ELF FileHeader: Class: ELFCLASS64 Index: llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml =================================================================== --- llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml +++ llvm/trunk/test/Object/yaml2obj-elf-symbol-visibility.yaml @@ -1,6 +1,6 @@ -# RUN: yaml2obj -format=elf %s | llvm-readobj -symbols - | \ +# RUN: yaml2obj %s | llvm-readobj -symbols - | \ # RUN: FileCheck --check-prefix OBJ %s -# RUN: yaml2obj -format=elf %s | obj2yaml - | FileCheck --check-prefix YAML %s +# RUN: yaml2obj %s | obj2yaml - | FileCheck --check-prefix YAML %s # OBJ: Symbol { # OBJ: Name: default1 (36) @@ -87,7 +87,7 @@ # YAML-NEXT: Visibility: STV_PROTECTED # YAML-NEXT: Other: [ STO_MIPS_PIC, STO_MIPS_MICROMIPS ] ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB Index: llvm/trunk/test/ObjectYAML/MachO/bind_opcode.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/bind_opcode.yaml +++ llvm/trunk/test/ObjectYAML/MachO/bind_opcode.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml +++ llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/dylib_dylinker_command.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/dylib_dylinker_command.yaml +++ llvm/trunk/test/ObjectYAML/MachO/dylib_dylinker_command.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml +++ llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml +++ llvm/trunk/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !fat-mach-o FatHeader: Index: llvm/trunk/test/ObjectYAML/MachO/lazy_bind_opcode.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/lazy_bind_opcode.yaml +++ llvm/trunk/test/ObjectYAML/MachO/lazy_bind_opcode.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/load_commands.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/load_commands.yaml +++ llvm/trunk/test/ObjectYAML/MachO/load_commands.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/mach_header.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/mach_header.yaml +++ llvm/trunk/test/ObjectYAML/MachO/mach_header.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/mach_header_32_malformed.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/mach_header_32_malformed.yaml +++ llvm/trunk/test/ObjectYAML/MachO/mach_header_32_malformed.yaml @@ -1,4 +1,4 @@ -# RUN: not yaml2obj -format=macho %s 2>&1 | FileCheck %s +# RUN: not yaml2obj %s 2>&1 | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml +++ llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/out_of_order_linkedit.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/out_of_order_linkedit.yaml +++ llvm/trunk/test/ObjectYAML/MachO/out_of_order_linkedit.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/rebase_opcode.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/rebase_opcode.yaml +++ llvm/trunk/test/ObjectYAML/MachO/rebase_opcode.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/sections.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/sections.yaml +++ llvm/trunk/test/ObjectYAML/MachO/sections.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/symtab.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/symtab.yaml +++ llvm/trunk/test/ObjectYAML/MachO/symtab.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/ObjectYAML/MachO/weak_bind_opcode.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/MachO/weak_bind_opcode.yaml +++ llvm/trunk/test/ObjectYAML/MachO/weak_bind_opcode.yaml @@ -1,4 +1,4 @@ -# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: Index: llvm/trunk/test/tools/llvm-ar/Inputs/coff.yaml =================================================================== --- llvm/trunk/test/tools/llvm-ar/Inputs/coff.yaml +++ llvm/trunk/test/tools/llvm-ar/Inputs/coff.yaml @@ -1,4 +1,4 @@ ---- +--- !COFF header: Machine: IMAGE_FILE_MACHINE_AMD64 Characteristics: [ ] Index: llvm/trunk/test/tools/llvm-ar/Inputs/elf.yaml =================================================================== --- llvm/trunk/test/tools/llvm-ar/Inputs/elf.yaml +++ llvm/trunk/test/tools/llvm-ar/Inputs/elf.yaml @@ -1,4 +1,4 @@ ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/tools/llvm-ar/default-add.test =================================================================== --- llvm/trunk/test/tools/llvm-ar/default-add.test +++ llvm/trunk/test/tools/llvm-ar/default-add.test @@ -1,5 +1,5 @@ -RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t-macho.o -RUN: yaml2obj -format coff %S/Inputs/coff.yaml -o %t-coff.o +RUN: yaml2obj %S/Inputs/macho.yaml -o %t-macho.o +RUN: yaml2obj %S/Inputs/coff.yaml -o %t-coff.o RUN: rm -f %t.ar RUN: llvm-ar crs %t.ar %t-macho.o Index: llvm/trunk/test/tools/llvm-ar/default-coff.test =================================================================== --- llvm/trunk/test/tools/llvm-ar/default-coff.test +++ llvm/trunk/test/tools/llvm-ar/default-coff.test @@ -1,4 +1,4 @@ -RUN: yaml2obj -format coff %S/Inputs/coff.yaml -o %t.obj +RUN: yaml2obj %S/Inputs/coff.yaml -o %t.obj RUN: rm -f %t.ar RUN: llvm-ar crs %t.ar %t.obj Index: llvm/trunk/test/tools/llvm-ar/default-elf.test =================================================================== --- llvm/trunk/test/tools/llvm-ar/default-elf.test +++ llvm/trunk/test/tools/llvm-ar/default-elf.test @@ -1,4 +1,4 @@ -RUN: yaml2obj -format elf %S/Inputs/elf.yaml -o %t.o +RUN: yaml2obj %S/Inputs/elf.yaml -o %t.o RUN: rm -f %t.ar RUN: llvm-ar crs %t.ar %t.o Index: llvm/trunk/test/tools/llvm-ar/default-macho.test =================================================================== --- llvm/trunk/test/tools/llvm-ar/default-macho.test +++ llvm/trunk/test/tools/llvm-ar/default-macho.test @@ -1,4 +1,4 @@ -RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t.o +RUN: yaml2obj %S/Inputs/macho.yaml -o %t.o RUN: rm -f %t.ar RUN: llvm-ar crs %t.ar %t.o Index: llvm/trunk/test/tools/llvm-ar/override.test =================================================================== --- llvm/trunk/test/tools/llvm-ar/override.test +++ llvm/trunk/test/tools/llvm-ar/override.test @@ -1,4 +1,4 @@ -RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t.o +RUN: yaml2obj %S/Inputs/macho.yaml -o %t.o RUN: rm -f %t.ar RUN: llvm-ar -format gnu crs %t.ar %t.o Index: llvm/trunk/test/tools/llvm-objdump/Inputs/file-aux-record.yaml =================================================================== --- llvm/trunk/test/tools/llvm-objdump/Inputs/file-aux-record.yaml +++ llvm/trunk/test/tools/llvm-objdump/Inputs/file-aux-record.yaml @@ -1,3 +1,4 @@ +!COFF header: !Header Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/tools/llvm-readobj/Inputs/file-aux-record.yaml =================================================================== --- llvm/trunk/test/tools/llvm-readobj/Inputs/file-aux-record.yaml +++ llvm/trunk/test/tools/llvm-readobj/Inputs/file-aux-record.yaml @@ -1,3 +1,4 @@ +!COFF header: !Header Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/tools/llvm-readobj/Inputs/file-multiple-aux-records.yaml =================================================================== --- llvm/trunk/test/tools/llvm-readobj/Inputs/file-multiple-aux-records.yaml +++ llvm/trunk/test/tools/llvm-readobj/Inputs/file-multiple-aux-records.yaml @@ -1,3 +1,4 @@ +!COFF header: !Header Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] Index: llvm/trunk/test/tools/llvm-readobj/elf-sec-flags.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/elf-sec-flags.test +++ llvm/trunk/test/tools/llvm-readobj/elf-sec-flags.test @@ -1,6 +1,6 @@ # Check that llvm-readobj shows arch specific ELF section flags. -# RUN: yaml2obj -format=elf -docnum 1 %s > %t-amdgpu.o +# RUN: yaml2obj -docnum 1 %s > %t-amdgpu.o # RUN: llvm-readobj -s %t-amdgpu.o | FileCheck -check-prefix=AMD %s # AMD: Flags [ (0x300000) @@ -9,7 +9,7 @@ # AMD-NEXT: ] # amdgpu.o ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB @@ -23,7 +23,7 @@ Flags: [SHF_AMDGPU_HSA_GLOBAL, SHF_AMDGPU_HSA_READONLY] Size: 4 -# RUN: yaml2obj -format=elf -docnum 2 %s > %t-hex.o +# RUN: yaml2obj -docnum 2 %s > %t-hex.o # RUN: llvm-readobj -s %t-hex.o | FileCheck -check-prefix=HEX %s # HEX: Flags [ (0x10000000) @@ -31,7 +31,7 @@ # HEX-NEXT: ] # hex.o ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB @@ -44,7 +44,7 @@ Flags: [SHF_HEX_GPREL] Size: 4 -# RUN: yaml2obj -format=elf -docnum 3 %s > %t-mips.o +# RUN: yaml2obj -docnum 3 %s > %t-mips.o # RUN: llvm-readobj -s %t-mips.o | FileCheck -check-prefix=MIPS %s # MIPS: Flags [ (0x38000000) @@ -54,7 +54,7 @@ # MIPS-NEXT: ] # mips.o ---- +--- !ELF FileHeader: Class: ELFCLASS32 Data: ELFDATA2LSB @@ -67,7 +67,7 @@ Flags: [SHF_MIPS_GPREL, SHF_MIPS_MERGE, SHF_MIPS_NOSTRIP] Size: 4 -# RUN: yaml2obj -format=elf -docnum 4 %s > %t-x86_64.o +# RUN: yaml2obj -docnum 4 %s > %t-x86_64.o # RUN: llvm-readobj -s %t-x86_64.o | FileCheck -check-prefix=X86_64 %s # X86_64: Flags [ (0x10000000) @@ -75,7 +75,7 @@ # X86_64-NEXT: ] # x86_64.o ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/tools/sanstats/elf.test =================================================================== --- llvm/trunk/test/tools/sanstats/elf.test +++ llvm/trunk/test/tools/sanstats/elf.test @@ -1,5 +1,5 @@ -# RUN: yaml2obj -format=elf %s > %t1.o -# RUN: yaml2obj -format=elf %s > %t2.o +# RUN: yaml2obj %s > %t1.o +# RUN: yaml2obj %s > %t2.o # RUN: echo -ne "\x04" > %t.stats @@ -39,7 +39,7 @@ # CHECK: /tmp{{[/\\]}}f.c:2 f2 cfi-icall 12 # CHECK: /tmp{{[/\\]}}f.c:1 f1 14 ---- +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Index: llvm/trunk/test/tools/yaml2obj/missing_document_tag.yaml =================================================================== --- llvm/trunk/test/tools/yaml2obj/missing_document_tag.yaml +++ llvm/trunk/test/tools/yaml2obj/missing_document_tag.yaml @@ -0,0 +1,6 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s + +--- +DummyData: + foo: 0 +... Index: llvm/trunk/test/tools/yaml2obj/unsupported_document_tag.yaml =================================================================== --- llvm/trunk/test/tools/yaml2obj/unsupported_document_tag.yaml +++ llvm/trunk/test/tools/yaml2obj/unsupported_document_tag.yaml @@ -0,0 +1,8 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s + +--- !unsupported-tag +DummyData: + foo: 0 +... + +#check error: YAML Object File unsupported document type tag '!unsupported-tag'! Index: llvm/trunk/tools/obj2yaml/macho2yaml.cpp =================================================================== --- llvm/trunk/tools/obj2yaml/macho2yaml.cpp +++ llvm/trunk/tools/obj2yaml/macho2yaml.cpp @@ -10,7 +10,7 @@ #include "Error.h" #include "obj2yaml.h" #include "llvm/Object/MachOUniversal.h" -#include "llvm/ObjectYAML/MachOYAML.h" +#include "llvm/ObjectYAML/ObjectYAML.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LEB128.h" @@ -467,15 +467,18 @@ if (!YAML) return YAML.takeError(); + yaml::YamlObjectFile YAMLFile; + YAMLFile.MachO = std::move(YAML.get()); + yaml::Output Yout(Out); - Yout << *(YAML.get()); + Yout << YAMLFile; return Error::success(); } Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) { - MachOYAML::MachFile YAMLFile; - YAMLFile.isFat = true; - MachOYAML::UniversalBinary &YAML = YAMLFile.FatFile; + yaml::YamlObjectFile YAMLFile; + YAMLFile.FatMachO.reset(new MachOYAML::UniversalBinary()); + MachOYAML::UniversalBinary &YAML = *YAMLFile.FatMachO; YAML.Header.magic = Obj.getMagic(); YAML.Header.nfat_arch = Obj.getNumberOfObjects(); Index: llvm/trunk/tools/yaml2obj/yaml2coff.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2coff.cpp +++ llvm/trunk/tools/yaml2obj/yaml2coff.cpp @@ -18,7 +18,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Object/COFF.h" -#include "llvm/ObjectYAML/COFFYAML.h" +#include "llvm/ObjectYAML/ObjectYAML.h" #include "llvm/Support/Endian.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -532,14 +532,7 @@ return true; } -int yaml2coff(yaml::Input &YIn, raw_ostream &Out) { - COFFYAML::Object Doc; - YIn >> Doc; - if (YIn.error()) { - errs() << "yaml2obj: Failed to parse YAML file!\n"; - return 1; - } - +int yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) { COFFParser CP(Doc); if (!CP.parse()) { errs() << "yaml2obj: Failed to parse YAML file!\n"; Index: llvm/trunk/tools/yaml2obj/yaml2elf.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2elf.cpp +++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp @@ -558,13 +558,7 @@ return Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); } -int yaml2elf(yaml::Input &YIn, raw_ostream &Out) { - ELFYAML::Object Doc; - YIn >> Doc; - if (YIn.error()) { - errs() << "yaml2obj: Failed to parse YAML file!\n"; - return 1; - } +int yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) { using object::ELFType; typedef ELFType LE64; typedef ELFType BE64; Index: llvm/trunk/tools/yaml2obj/yaml2macho.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2macho.cpp +++ llvm/trunk/tools/yaml2obj/yaml2macho.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "yaml2obj.h" -#include "llvm/ObjectYAML/MachOYAML.h" +#include "llvm/ObjectYAML/ObjectYAML.h" #include "llvm/Support/Error.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/MachO.h" @@ -426,8 +426,8 @@ class UniversalWriter { public: - UniversalWriter(MachOYAML::MachFile &MachFile) - : MachFile(MachFile), fileStart(0) {} + UniversalWriter(yaml::YamlObjectFile &ObjectFile) + : ObjectFile(ObjectFile), fileStart(0) {} Error writeMachO(raw_ostream &OS); @@ -437,21 +437,21 @@ void ZeroToOffset(raw_ostream &OS, size_t offset); - MachOYAML::MachFile &MachFile; + yaml::YamlObjectFile &ObjectFile; uint64_t fileStart; }; Error UniversalWriter::writeMachO(raw_ostream &OS) { fileStart = OS.tell(); - if (!MachFile.isFat) { - MachOWriter Writer(MachFile.ThinFile); + if (ObjectFile.MachO) { + MachOWriter Writer(*ObjectFile.MachO); return Writer.writeMachO(OS); } if (auto Err = writeFatHeader(OS)) return Err; if (auto Err = writeFatArchs(OS)) return Err; - auto &FatFile = MachFile.FatFile; + auto &FatFile = *ObjectFile.FatMachO; assert(FatFile.FatArchs.size() == FatFile.Slices.size()); for (size_t i = 0; i < FatFile.Slices.size(); i++) { ZeroToOffset(OS, FatFile.FatArchs[i].offset); @@ -465,7 +465,7 @@ } Error UniversalWriter::writeFatHeader(raw_ostream &OS) { - auto &FatFile = MachFile.FatFile; + auto &FatFile = *ObjectFile.FatMachO; MachO::fat_header header; header.magic = FatFile.Header.magic; header.nfat_arch = FatFile.Header.nfat_arch; @@ -509,7 +509,7 @@ } Error UniversalWriter::writeFatArchs(raw_ostream &OS) { - auto &FatFile = MachFile.FatFile; + auto &FatFile = *ObjectFile.FatMachO; bool is64Bit = FatFile.Header.magic == MachO::FAT_MAGIC_64; for (auto Arch : FatFile.FatArchs) { if (is64Bit) @@ -529,14 +529,7 @@ } // end anonymous namespace -int yaml2macho(yaml::Input &YIn, raw_ostream &Out) { - MachOYAML::MachFile Doc; - YIn >> Doc; - if (YIn.error()) { - errs() << "yaml2obj: Failed to parse YAML file!\n"; - return 1; - } - +int yaml2macho(yaml::YamlObjectFile &Doc, raw_ostream &Out) { UniversalWriter Writer(Doc); if (auto Err = Writer.writeMachO(Out)) { errs() << toString(std::move(Err)); Index: llvm/trunk/tools/yaml2obj/yaml2obj.h =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2obj.h +++ llvm/trunk/tools/yaml2obj/yaml2obj.h @@ -14,12 +14,23 @@ namespace llvm { class raw_ostream; + +namespace COFFYAML { +struct Object; +} + +namespace ELFYAML { +struct Object; +} + namespace yaml { class Input; +struct YamlObjectFile; } } -int yaml2coff(llvm::yaml::Input &YIn, llvm::raw_ostream &Out); -int yaml2elf(llvm::yaml::Input &YIn, llvm::raw_ostream &Out); -int yaml2macho(llvm::yaml::Input &YIn, llvm::raw_ostream &Out); + +int yaml2coff(llvm::COFFYAML::Object &Doc, llvm::raw_ostream &Out); +int yaml2elf(llvm::ELFYAML::Object &Doc, llvm::raw_ostream &Out); +int yaml2macho(llvm::yaml::YamlObjectFile &Doc, llvm::raw_ostream &Out); #endif Index: llvm/trunk/tools/yaml2obj/yaml2obj.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2obj.cpp +++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp @@ -16,6 +16,7 @@ #include "yaml2obj.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ObjectYAML/ObjectYAML.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" @@ -32,29 +33,6 @@ static cl::opt Input(cl::Positional, cl::desc(""), cl::init("-")); -// TODO: The "right" way to tell what kind of object file a given YAML file -// corresponds to is to look at YAML "tags" (e.g. `!Foo`). Then, different -// tags (`!ELF`, `!COFF`, etc.) would be used to discriminate between them. -// Interpreting the tags is needed eventually for when writing test cases, -// so that we can e.g. have `!Archive` contain a sequence of `!ELF`, and -// just Do The Right Thing. However, interpreting these tags and acting on -// them appropriately requires some work in the YAML parser and the YAMLIO -// library. -enum YAMLObjectFormat { - YOF_COFF, - YOF_ELF, - YOF_MACHO -}; - -cl::opt Format( - "format", - cl::desc("Interpret input as this type of object file"), - cl::values( - clEnumValN(YOF_COFF, "coff", "COFF object file format"), - clEnumValN(YOF_ELF, "elf", "ELF object file format"), - clEnumValN(YOF_MACHO, "macho", "Mach-O object file format"), - clEnumValEnd)); - cl::opt DocNum("docnum", cl::init(1), cl::desc("Read specified document from input (default = 1)")); @@ -62,14 +40,26 @@ static cl::opt OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); -typedef int (*ConvertFuncPtr)(yaml::Input & YIn, raw_ostream &Out); - -static int convertYAML(yaml::Input &YIn, raw_ostream &Out, - ConvertFuncPtr Convert) { +static int convertYAML(yaml::Input &YIn, raw_ostream &Out) { unsigned CurDocNum = 0; do { - if (++CurDocNum == DocNum) - return Convert(YIn, Out); + if (++CurDocNum == DocNum) { + yaml::YamlObjectFile Doc; + YIn >> Doc; + if (YIn.error()) { + errs() << "yaml2obj: Failed to parse YAML file!\n"; + return 1; + } + + if (Doc.Elf) + return yaml2elf(*Doc.Elf, Out); + if (Doc.Coff) + return yaml2coff(*Doc.Coff, Out); + if (Doc.MachO || Doc.FatMachO) + return yaml2macho(Doc, Out); + errs() << "yaml2obj: Unknown document type!\n"; + return 1; + } } while (YIn.nextDocument()); errs() << "yaml2obj: Cannot find the " << DocNum @@ -99,21 +89,9 @@ if (!Buf) return 1; - ConvertFuncPtr Convert = nullptr; - if (Format == YOF_COFF) - Convert = yaml2coff; - else if (Format == YOF_ELF) - Convert = yaml2elf; - else if (Format == YOF_MACHO) - Convert = yaml2macho; - else { - errs() << "Not yet implemented\n"; - return 1; - } - yaml::Input YIn(Buf.get()->getBuffer()); - int Res = convertYAML(YIn, Out->os(), Convert); + int Res = convertYAML(YIn, Out->os()); if (Res == 0) Out->keep();