1 //===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a wrapper class for handling tagged YAML input
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ObjectYAML/YAML.h"
15 #include "llvm/ObjectYAML/ObjectYAML.h"
16
17 using namespace llvm;
18 using namespace yaml;
19
mapping(IO & IO,YamlObjectFile & ObjectFile)20 void MappingTraits<YamlObjectFile>::mapping(IO &IO,
21 YamlObjectFile &ObjectFile) {
22 if (IO.outputting()) {
23 if (ObjectFile.Elf)
24 MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
25 if (ObjectFile.Coff)
26 MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
27 if (ObjectFile.MachO)
28 MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
29 if (ObjectFile.FatMachO)
30 MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
31 *ObjectFile.FatMachO);
32 } else {
33 if (IO.mapTag("!ELF")) {
34 ObjectFile.Elf.reset(new ELFYAML::Object());
35 MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
36 } else if (IO.mapTag("!COFF")) {
37 ObjectFile.Coff.reset(new COFFYAML::Object());
38 MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
39 } else if (IO.mapTag("!mach-o")) {
40 ObjectFile.MachO.reset(new MachOYAML::Object());
41 MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
42 } else if (IO.mapTag("!fat-mach-o")) {
43 ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
44 MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
45 *ObjectFile.FatMachO);
46 } else {
47 Input &In = (Input &)IO;
48 std::string Tag = In.getCurrentNode()->getRawTag();
49 if (Tag.empty())
50 IO.setError("YAML Object File missing document type tag!");
51 else
52 IO.setError(
53 llvm::Twine("YAML Object File unsupported document type tag '") +
54 llvm::Twine(Tag.c_str()) + llvm::Twine("'!"));
55 }
56 }
57 }
58