| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 1 | //===- ObjectYAML.cpp - YAML utilities for object files -------------------===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines a wrapper class for handling tagged YAML input |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 13 | #include "llvm/ObjectYAML/ObjectYAML.h" |
| Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/Twine.h" |
| 15 | #include "llvm/Support/YAMLParser.h" |
| 16 | #include "llvm/Support/YAMLTraits.h" |
| 17 | #include <string> |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | using namespace yaml; |
| 21 | |
| 22 | void MappingTraits<YamlObjectFile>::mapping(IO &IO, |
| 23 | YamlObjectFile &ObjectFile) { |
| 24 | if (IO.outputting()) { |
| 25 | if (ObjectFile.Elf) |
| 26 | MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); |
| 27 | if (ObjectFile.Coff) |
| 28 | MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff); |
| 29 | if (ObjectFile.MachO) |
| 30 | MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO); |
| 31 | if (ObjectFile.FatMachO) |
| 32 | MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, |
| 33 | *ObjectFile.FatMachO); |
| 34 | } else { |
| George Rimar | 45d042e | 2019-04-25 09:59:55 +0000 | [diff] [blame] | 35 | Input &In = (Input &)IO; |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 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); |
| Pavel Labath | 69de7a9 | 2019-03-22 14:47:26 +0000 | [diff] [blame] | 49 | } else if (IO.mapTag("!minidump")) { |
| 50 | ObjectFile.Minidump.reset(new MinidumpYAML::Object()); |
| 51 | MappingTraits<MinidumpYAML::Object>::mapping(IO, *ObjectFile.Minidump); |
| Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 52 | } else if (IO.mapTag("!WASM")) { |
| 53 | ObjectFile.Wasm.reset(new WasmYAML::Object()); |
| 54 | MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm); |
| George Rimar | 45d042e | 2019-04-25 09:59:55 +0000 | [diff] [blame] | 55 | } else if (const Node *N = In.getCurrentNode()) { |
| 56 | if (N->getRawTag().empty()) |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 57 | IO.setError("YAML Object File missing document type tag!"); |
| 58 | else |
| George Rimar | 45d042e | 2019-04-25 09:59:55 +0000 | [diff] [blame] | 59 | IO.setError("YAML Object File unsupported document type tag '" + |
| 60 | N->getRawTag() + "'!"); |
| Chris Bieneman | 8ff0c11 | 2016-06-27 19:53:53 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |