Chris Bieneman | 9cf90e6 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 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 | |
Chris Bieneman | 9cf90e6 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 14 | #include "llvm/ObjectYAML/ObjectYAML.h" |
Eugene Zelenko | cd90344 | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Twine.h" |
| 16 | #include "llvm/Support/YAMLParser.h" |
| 17 | #include "llvm/Support/YAMLTraits.h" |
| 18 | #include <string> |
Chris Bieneman | 9cf90e6 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | using namespace yaml; |
| 22 | |
| 23 | void MappingTraits<YamlObjectFile>::mapping(IO &IO, |
| 24 | YamlObjectFile &ObjectFile) { |
| 25 | if (IO.outputting()) { |
| 26 | if (ObjectFile.Elf) |
| 27 | MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); |
| 28 | if (ObjectFile.Coff) |
| 29 | MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff); |
| 30 | if (ObjectFile.MachO) |
| 31 | MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO); |
| 32 | if (ObjectFile.FatMachO) |
| 33 | MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, |
| 34 | *ObjectFile.FatMachO); |
| 35 | } else { |
| 36 | if (IO.mapTag("!ELF")) { |
| 37 | ObjectFile.Elf.reset(new ELFYAML::Object()); |
| 38 | MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); |
| 39 | } else if (IO.mapTag("!COFF")) { |
| 40 | ObjectFile.Coff.reset(new COFFYAML::Object()); |
| 41 | MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff); |
| 42 | } else if (IO.mapTag("!mach-o")) { |
| 43 | ObjectFile.MachO.reset(new MachOYAML::Object()); |
| 44 | MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO); |
| 45 | } else if (IO.mapTag("!fat-mach-o")) { |
| 46 | ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary()); |
| 47 | MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, |
| 48 | *ObjectFile.FatMachO); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 49 | } else if (IO.mapTag("!WASM")) { |
| 50 | ObjectFile.Wasm.reset(new WasmYAML::Object()); |
| 51 | MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm); |
Chris Bieneman | 9cf90e6 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 52 | } else { |
| 53 | Input &In = (Input &)IO; |
| 54 | std::string Tag = In.getCurrentNode()->getRawTag(); |
| 55 | if (Tag.empty()) |
| 56 | IO.setError("YAML Object File missing document type tag!"); |
| 57 | else |
| 58 | IO.setError( |
Eugene Zelenko | cd90344 | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 59 | Twine("YAML Object File unsupported document type tag '") + |
| 60 | Twine(Tag) + Twine("'!")); |
Chris Bieneman | 9cf90e6 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |