Add a SymbolRef::getValue.
[oota-llvm.git] / include / llvm / Object / COFFYAML.h
index 4c20260222f325b5860637d2436537b1d10d68f6..12a25223bd37e71016de9f7c899068d558f87edd 100644 (file)
@@ -14,9 +14,9 @@
 #ifndef LLVM_OBJECT_COFFYAML_H
 #define LLVM_OBJECT_COFFYAML_H
 
-
+#include "llvm/ADT/Optional.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/Support/COFF.h"
-#include "llvm/Support/YAMLTraits.h"
 
 namespace llvm {
 
@@ -31,38 +31,32 @@ inline SectionCharacteristics operator|(SectionCharacteristics a,
   uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b);
   return static_cast<SectionCharacteristics>(Ret);
 }
+
+inline DLLCharacteristics operator|(DLLCharacteristics a,
+                                    DLLCharacteristics b) {
+  uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b);
+  return static_cast<DLLCharacteristics>(Ret);
+}
 }
 
 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
 // to use yaml::IO, we use these structures which are closer to the source.
 namespace COFFYAML {
-  /// In an object file this is just a binary blob. In an yaml file it is an hex
-  /// string. Using this avoid having to allocate temporary strings.
-  /// FIXME: not COFF specific.
-  class BinaryRef {
-    ArrayRef<uint8_t> Data;
-    bool isBinary;
-  public:
-    BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), isBinary(true) {}
-    BinaryRef(StringRef Data)
-        : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()),
-          isBinary(false) {}
-    BinaryRef() : isBinary(false) {}
-    StringRef getHex() const {
-      assert(!isBinary);
-      return StringRef(reinterpret_cast<const char*>(Data.data()), Data.size());
-    }
-    ArrayRef<uint8_t> getBinary() const {
-      assert(isBinary);
-      return Data;
-    }
+  LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
+  LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
+  LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
+
+  struct Relocation {
+    uint32_t VirtualAddress;
+    uint16_t Type;
+    StringRef SymbolName;
   };
 
   struct Section {
     COFF::section Header;
     unsigned Alignment;
-    BinaryRef SectionData;
-    std::vector<COFF::relocation> Relocations;
+    yaml::BinaryRef SectionData;
+    std::vector<Relocation> Relocations;
     StringRef Name;
     Section();
   };
@@ -71,12 +65,23 @@ namespace COFFYAML {
     COFF::symbol Header;
     COFF::SymbolBaseType SimpleType;
     COFF::SymbolComplexType ComplexType;
-    BinaryRef AuxiliaryData;
+    Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition;
+    Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol;
+    Optional<COFF::AuxiliaryWeakExternal> WeakExternal;
+    StringRef File;
+    Optional<COFF::AuxiliarySectionDefinition> SectionDefinition;
+    Optional<COFF::AuxiliaryCLRToken> CLRToken;
     StringRef Name;
     Symbol();
   };
 
+  struct PEHeader {
+    COFF::PE32Header Header;
+    Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES];
+  };
+
   struct Object {
+    Optional<PEHeader> OptionalHeader;
     COFF::header Header;
     std::vector<Section> Sections;
     std::vector<Symbol> Symbols;
@@ -87,15 +92,24 @@ namespace COFFYAML {
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
-LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
+LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
 
 namespace llvm {
 namespace yaml {
 
-template<>
-struct ScalarTraits<COFFYAML::BinaryRef> {
-  static void output(const COFFYAML::BinaryRef &, void*, llvm::raw_ostream &);
-  static StringRef input(StringRef, void*, COFFYAML::BinaryRef &);
+template <>
+struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> {
+  static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
+};
+
+template <>
+struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> {
+  static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
+};
+
+template <>
+struct ScalarEnumerationTraits<COFFYAML::COMDATType> {
+  static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
 };
 
 template <>
@@ -119,8 +133,18 @@ struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
 };
 
 template <>
-struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
-  static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value);
+struct ScalarEnumerationTraits<COFF::RelocationTypeI386> {
+  static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
+};
+
+template <>
+struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> {
+  static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
+};
+
+template <>
+struct ScalarEnumerationTraits<COFF::WindowsSubsystem> {
+  static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
 };
 
 template <>
@@ -134,8 +158,23 @@ struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
 };
 
 template <>
-struct MappingTraits<COFF::relocation> {
-  static void mapping(IO &IO, COFF::relocation &Rel);
+struct ScalarBitSetTraits<COFF::DLLCharacteristics> {
+  static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
+};
+
+template <>
+struct MappingTraits<COFFYAML::Relocation> {
+  static void mapping(IO &IO, COFFYAML::Relocation &Rel);
+};
+
+template <>
+struct MappingTraits<COFFYAML::PEHeader> {
+  static void mapping(IO &IO, COFFYAML::PEHeader &PH);
+};
+
+template <>
+struct MappingTraits<COFF::DataDirectory> {
+  static void mapping(IO &IO, COFF::DataDirectory &DD);
 };
 
 template <>
@@ -143,6 +182,26 @@ struct MappingTraits<COFF::header> {
   static void mapping(IO &IO, COFF::header &H);
 };
 
+template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> {
+  static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
+};
+
+template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> {
+  static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
+};
+
+template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> {
+  static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
+};
+
+template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> {
+  static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
+};
+
+template <> struct MappingTraits<COFF::AuxiliaryCLRToken> {
+  static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
+};
+
 template <>
 struct MappingTraits<COFFYAML::Symbol> {
   static void mapping(IO &IO, COFFYAML::Symbol &S);