Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / ObjectYAML / ObjectYAML.cpp
blob42353972103f6ad092097c0fa45e5fb9119964b3
1 //===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a wrapper class for handling tagged YAML input
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/ObjectYAML.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/YAMLParser.h"
16 #include "llvm/Support/YAMLTraits.h"
17 #include <string>
19 using namespace llvm;
20 using namespace yaml;
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 {
35 if (IO.mapTag("!ELF")) {
36 ObjectFile.Elf.reset(new ELFYAML::Object());
37 MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
38 } else if (IO.mapTag("!COFF")) {
39 ObjectFile.Coff.reset(new COFFYAML::Object());
40 MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
41 } else if (IO.mapTag("!mach-o")) {
42 ObjectFile.MachO.reset(new MachOYAML::Object());
43 MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
44 } else if (IO.mapTag("!fat-mach-o")) {
45 ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
46 MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
47 *ObjectFile.FatMachO);
48 } else if (IO.mapTag("!WASM")) {
49 ObjectFile.Wasm.reset(new WasmYAML::Object());
50 MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm);
51 } else {
52 Input &In = (Input &)IO;
53 std::string Tag = In.getCurrentNode()->getRawTag();
54 if (Tag.empty())
55 IO.setError("YAML Object File missing document type tag!");
56 else
57 IO.setError(
58 Twine("YAML Object File unsupported document type tag '") +
59 Twine(Tag) + Twine("'!"));