1 //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares classes for handling the YAML representation of COFF.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_COFFYAML_H
15 #define LLVM_OBJECT_COFFYAML_H
18 #include "llvm/Support/COFF.h"
19 #include "llvm/Support/YAMLTraits.h"
24 inline Characteristics operator|(Characteristics a, Characteristics b) {
25 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
26 return static_cast<Characteristics>(Ret);
29 inline SectionCharacteristics operator|(SectionCharacteristics a,
30 SectionCharacteristics b) {
31 uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
32 return static_cast<SectionCharacteristics>(Ret);
36 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
37 // to use yaml::IO, we use these structures which are closer to the source.
39 /// In an object file this is just a binary blob. In an yaml file it is an hex
40 /// string. Using this avoid having to allocate temporary strings.
41 /// FIXME: not COFF specific.
43 ArrayRef<uint8_t> Data;
46 BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), isBinary(true) {}
47 BinaryRef(StringRef Data)
48 : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()),
50 BinaryRef() : isBinary(false) {}
51 StringRef getHex() const {
53 return StringRef(reinterpret_cast<const char*>(Data.data()), Data.size());
55 ArrayRef<uint8_t> getBinary() const {
64 BinaryRef SectionData;
65 std::vector<COFF::relocation> Relocations;
72 COFF::SymbolBaseType SimpleType;
73 COFF::SymbolComplexType ComplexType;
74 BinaryRef AuxiliaryData;
81 std::vector<Section> Sections;
82 std::vector<Symbol> Symbols;
88 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
89 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
90 LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
96 struct ScalarTraits<COFFYAML::BinaryRef> {
97 static void output(const COFFYAML::BinaryRef &, void*, llvm::raw_ostream &);
98 static StringRef input(StringRef, void*, COFFYAML::BinaryRef &);
102 struct ScalarEnumerationTraits<COFF::MachineTypes> {
103 static void enumeration(IO &IO, COFF::MachineTypes &Value);
107 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
108 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
112 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
113 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
117 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
118 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
122 struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
123 static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
127 struct ScalarBitSetTraits<COFF::Characteristics> {
128 static void bitset(IO &IO, COFF::Characteristics &Value);
132 struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
133 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
137 struct MappingTraits<COFF::relocation> {
138 static void mapping(IO &IO, COFF::relocation &Rel);
142 struct MappingTraits<COFF::header> {
143 static void mapping(IO &IO, COFF::header &H);
147 struct MappingTraits<COFFYAML::Symbol> {
148 static void mapping(IO &IO, COFFYAML::Symbol &S);
152 struct MappingTraits<COFFYAML::Section> {
153 static void mapping(IO &IO, COFFYAML::Section &Sec);
157 struct MappingTraits<COFFYAML::Object> {
158 static void mapping(IO &IO, COFFYAML::Object &Obj);
161 } // end namespace yaml
162 } // end namespace llvm