LLVM  4.0.0
ObjectYAML.cpp
Go to the documentation of this file.
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 
14 #include "llvm/ObjectYAML/YAML.h"
16 
17 using namespace llvm;
18 using namespace yaml;
19 
22  if (IO.outputting()) {
23  if (ObjectFile.Elf)
25  if (ObjectFile.Coff)
27  if (ObjectFile.MachO)
29  if (ObjectFile.FatMachO)
31  *ObjectFile.FatMachO);
32  } else {
33  if (IO.mapTag("!ELF")) {
34  ObjectFile.Elf.reset(new ELFYAML::Object());
36  } else if (IO.mapTag("!COFF")) {
37  ObjectFile.Coff.reset(new COFFYAML::Object());
39  } else if (IO.mapTag("!mach-o")) {
40  ObjectFile.MachO.reset(new MachOYAML::Object());
42  } else if (IO.mapTag("!fat-mach-o")) {
43  ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
45  *ObjectFile.FatMachO);
46  } else {
47  Input &In = (Input &)IO;
48  std::string Tag = In.getCurrentNode()->getRawTag();
49  if (Tag.empty())
50  IO.setError("YAML Object File missing document type tag!");
51  else
52  IO.setError(
53  llvm::Twine("YAML Object File unsupported document type tag '") +
54  llvm::Twine(Tag) + llvm::Twine("'!"));
55  }
56  }
57 }
StringRef getRawTag() const
Get the tag as it was written in the document.
Definition: YAMLParser.h:128
This class is the base class for all object file types.
Definition: ObjectFile.h:178
virtual void setError(const Twine &)=0
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:1099
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
std::unique_ptr< COFFYAML::Object > Coff
Definition: ObjectYAML.h:23
virtual bool mapTag(StringRef Tag, bool Default=false)=0
const Node * getCurrentNode() const
Returns the current node that's being parsed by the YAML Parser.
Definition: YAMLTraits.cpp:97
std::unique_ptr< MachOYAML::Object > MachO
Definition: ObjectYAML.h:24
std::unique_ptr< MachOYAML::UniversalBinary > FatMachO
Definition: ObjectYAML.h:25
virtual bool outputting()=0
std::unique_ptr< ELFYAML::Object > Elf
Definition: ObjectYAML.h:22