2016-06-27 19:53:53 +00:00
|
|
|
//===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a wrapper class for handling tagged YAML input
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ObjectYAML/ObjectYAML.h"
|
2017-07-01 01:35:55 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Support/YAMLParser.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
#include <string>
|
2016-06-27 19:53:53 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace yaml;
|
|
|
|
|
|
|
|
void MappingTraits<YamlObjectFile>::mapping(IO &IO,
|
|
|
|
YamlObjectFile &ObjectFile) {
|
|
|
|
if (IO.outputting()) {
|
|
|
|
if (ObjectFile.Elf)
|
|
|
|
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
|
|
|
if (ObjectFile.Coff)
|
|
|
|
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
|
|
|
if (ObjectFile.MachO)
|
|
|
|
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
|
|
|
if (ObjectFile.FatMachO)
|
|
|
|
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
|
|
|
*ObjectFile.FatMachO);
|
|
|
|
} else {
|
|
|
|
if (IO.mapTag("!ELF")) {
|
|
|
|
ObjectFile.Elf.reset(new ELFYAML::Object());
|
|
|
|
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
|
|
|
} else if (IO.mapTag("!COFF")) {
|
|
|
|
ObjectFile.Coff.reset(new COFFYAML::Object());
|
|
|
|
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
|
|
|
} else if (IO.mapTag("!mach-o")) {
|
|
|
|
ObjectFile.MachO.reset(new MachOYAML::Object());
|
|
|
|
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
|
|
|
} else if (IO.mapTag("!fat-mach-o")) {
|
|
|
|
ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
|
|
|
|
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
|
|
|
*ObjectFile.FatMachO);
|
2017-03-30 19:44:09 +00:00
|
|
|
} else if (IO.mapTag("!WASM")) {
|
|
|
|
ObjectFile.Wasm.reset(new WasmYAML::Object());
|
|
|
|
MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm);
|
2016-06-27 19:53:53 +00:00
|
|
|
} else {
|
|
|
|
Input &In = (Input &)IO;
|
|
|
|
std::string Tag = In.getCurrentNode()->getRawTag();
|
|
|
|
if (Tag.empty())
|
|
|
|
IO.setError("YAML Object File missing document type tag!");
|
|
|
|
else
|
|
|
|
IO.setError(
|
2017-07-01 01:35:55 +00:00
|
|
|
Twine("YAML Object File unsupported document type tag '") +
|
|
|
|
Twine(Tag) + Twine("'!"));
|
2016-06-27 19:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|