1 //===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
22 void MappingTraits
<YamlObjectFile
>::mapping(IO
&IO
,
23 YamlObjectFile
&ObjectFile
) {
24 if (IO
.outputting()) {
26 MappingTraits
<ELFYAML::Object
>::mapping(IO
, *ObjectFile
.Elf
);
28 MappingTraits
<COFFYAML::Object
>::mapping(IO
, *ObjectFile
.Coff
);
30 MappingTraits
<MachOYAML::Object
>::mapping(IO
, *ObjectFile
.MachO
);
31 if (ObjectFile
.FatMachO
)
32 MappingTraits
<MachOYAML::UniversalBinary
>::mapping(IO
,
33 *ObjectFile
.FatMachO
);
35 Input
&In
= (Input
&)IO
;
36 if (IO
.mapTag("!Arch")) {
37 ObjectFile
.Arch
.reset(new ArchYAML::Archive());
38 MappingTraits
<ArchYAML::Archive
>::mapping(IO
, *ObjectFile
.Arch
);
40 MappingTraits
<ArchYAML::Archive
>::validate(IO
, *ObjectFile
.Arch
);
43 } else if (IO
.mapTag("!ELF")) {
44 ObjectFile
.Elf
.reset(new ELFYAML::Object());
45 MappingTraits
<ELFYAML::Object
>::mapping(IO
, *ObjectFile
.Elf
);
46 } else if (IO
.mapTag("!COFF")) {
47 ObjectFile
.Coff
.reset(new COFFYAML::Object());
48 MappingTraits
<COFFYAML::Object
>::mapping(IO
, *ObjectFile
.Coff
);
49 } else if (IO
.mapTag("!mach-o")) {
50 ObjectFile
.MachO
.reset(new MachOYAML::Object());
51 MappingTraits
<MachOYAML::Object
>::mapping(IO
, *ObjectFile
.MachO
);
52 } else if (IO
.mapTag("!fat-mach-o")) {
53 ObjectFile
.FatMachO
.reset(new MachOYAML::UniversalBinary());
54 MappingTraits
<MachOYAML::UniversalBinary
>::mapping(IO
,
55 *ObjectFile
.FatMachO
);
56 } else if (IO
.mapTag("!minidump")) {
57 ObjectFile
.Minidump
.reset(new MinidumpYAML::Object());
58 MappingTraits
<MinidumpYAML::Object
>::mapping(IO
, *ObjectFile
.Minidump
);
59 } else if (IO
.mapTag("!Offload")) {
60 ObjectFile
.Offload
.reset(new OffloadYAML::Binary());
61 MappingTraits
<OffloadYAML::Binary
>::mapping(IO
, *ObjectFile
.Offload
);
62 } else if (IO
.mapTag("!WASM")) {
63 ObjectFile
.Wasm
.reset(new WasmYAML::Object());
64 MappingTraits
<WasmYAML::Object
>::mapping(IO
, *ObjectFile
.Wasm
);
65 } else if (IO
.mapTag("!XCOFF")) {
66 ObjectFile
.Xcoff
.reset(new XCOFFYAML::Object());
67 MappingTraits
<XCOFFYAML::Object
>::mapping(IO
, *ObjectFile
.Xcoff
);
68 } else if (IO
.mapTag("!dxcontainer")) {
69 ObjectFile
.DXContainer
.reset(new DXContainerYAML::Object());
70 MappingTraits
<DXContainerYAML::Object
>::mapping(IO
,
71 *ObjectFile
.DXContainer
);
72 } else if (const Node
*N
= In
.getCurrentNode()) {
73 if (N
->getRawTag().empty())
74 IO
.setError("YAML Object File missing document type tag!");
76 IO
.setError("YAML Object File unsupported document type tag '" +
77 N
->getRawTag() + "'!");