[llvm] r183287 - Move BinaryRef to a new include/llvm/Object/YAML.h file.

Rafael Espindola rafael.espindola at gmail.com
Tue Jun 4 19:32:26 PDT 2013


Author: rafael
Date: Tue Jun  4 21:32:26 2013
New Revision: 183287

URL: http://llvm.org/viewvc/llvm-project?rev=183287&view=rev
Log:
Move BinaryRef to a new include/llvm/Object/YAML.h file.

It will be used for ELF dumping too.

Added:
    llvm/trunk/include/llvm/Object/YAML.h
    llvm/trunk/lib/Object/YAML.cpp
Modified:
    llvm/trunk/include/llvm/Object/COFFYAML.h
    llvm/trunk/lib/Object/CMakeLists.txt
    llvm/trunk/lib/Object/COFFYAML.cpp
    llvm/trunk/tools/obj2yaml/coff2yaml.cpp

Modified: llvm/trunk/include/llvm/Object/COFFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFFYAML.h?rev=183287&r1=183286&r2=183287&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFFYAML.h (original)
+++ llvm/trunk/include/llvm/Object/COFFYAML.h Tue Jun  4 21:32:26 2013
@@ -14,9 +14,8 @@
 #ifndef LLVM_OBJECT_COFFYAML_H
 #define LLVM_OBJECT_COFFYAML_H
 
-
+#include "llvm/Object/YAML.h"
 #include "llvm/Support/COFF.h"
-#include "llvm/Support/YAMLTraits.h"
 
 namespace llvm {
 
@@ -36,32 +35,10 @@ inline SectionCharacteristics operator|(
 // 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;
-    }
-  };
-
   struct Section {
     COFF::section Header;
     unsigned Alignment;
-    BinaryRef SectionData;
+    object::yaml::BinaryRef SectionData;
     std::vector<COFF::relocation> Relocations;
     StringRef Name;
     Section();
@@ -71,7 +48,7 @@ namespace COFFYAML {
     COFF::symbol Header;
     COFF::SymbolBaseType SimpleType;
     COFF::SymbolComplexType ComplexType;
-    BinaryRef AuxiliaryData;
+    object::yaml::BinaryRef AuxiliaryData;
     StringRef Name;
     Symbol();
   };
@@ -92,12 +69,6 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::reloc
 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<COFF::MachineTypes> {
   static void enumeration(IO &IO, COFF::MachineTypes &Value);

Added: llvm/trunk/include/llvm/Object/YAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/YAML.h?rev=183287&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Object/YAML.h (added)
+++ llvm/trunk/include/llvm/Object/YAML.h Tue Jun  4 21:32:26 2013
@@ -0,0 +1,59 @@
+//===- YAML.h - YAMLIO utilities for object files ---------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares utility classes for handling the YAML representation of
+// object files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_OBJECT_YAML_H
+#define LLVM_OBJECT_YAML_H
+
+#include "llvm/Support/YAMLTraits.h"
+
+namespace llvm {
+namespace object {
+namespace yaml {
+
+/// 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.
+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;
+  }
+};
+
+}
+}
+
+namespace yaml {
+template <> struct ScalarTraits<object::yaml::BinaryRef> {
+  static void output(const object::yaml::BinaryRef &, void *,
+                     llvm::raw_ostream &);
+  static StringRef input(StringRef, void *, object::yaml::BinaryRef &);
+};
+}
+
+}
+
+#endif

Modified: llvm/trunk/lib/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/CMakeLists.txt?rev=183287&r1=183286&r2=183287&view=diff
==============================================================================
--- llvm/trunk/lib/Object/CMakeLists.txt (original)
+++ llvm/trunk/lib/Object/CMakeLists.txt Tue Jun  4 21:32:26 2013
@@ -8,4 +8,5 @@ add_llvm_library(LLVMObject
   MachOObjectFile.cpp
   Object.cpp
   ObjectFile.cpp
+  YAML.cpp
   )

Modified: llvm/trunk/lib/Object/COFFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFYAML.cpp?rev=183287&r1=183286&r2=183287&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFYAML.cpp (original)
+++ llvm/trunk/lib/Object/COFFYAML.cpp Tue Jun  4 21:32:26 2013
@@ -229,23 +229,6 @@ struct NType {
 
 }
 
-void ScalarTraits<COFFYAML::BinaryRef>::output(const COFFYAML::BinaryRef &Val,
-                                               void *, llvm::raw_ostream &Out) {
-  ArrayRef<uint8_t> Data = Val.getBinary();
-  for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
-       ++I) {
-    uint8_t Byte = *I;
-    Out << hexdigit(Byte >> 4);
-    Out << hexdigit(Byte & 0xf);
-  }
-}
-
-StringRef ScalarTraits<COFFYAML::BinaryRef>::input(StringRef Scalar, void *,
-                                                   COFFYAML::BinaryRef &Val) {
-  Val = COFFYAML::BinaryRef(Scalar);
-  return StringRef();
-}
-
 void MappingTraits<COFF::relocation>::mapping(IO &IO, COFF::relocation &Rel) {
   MappingNormalization<NType, uint16_t> NT(IO, Rel.Type);
 

Added: llvm/trunk/lib/Object/YAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/YAML.cpp?rev=183287&view=auto
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (added)
+++ llvm/trunk/lib/Object/YAML.cpp Tue Jun  4 21:32:26 2013
@@ -0,0 +1,34 @@
+//===- YAML.cpp - YAMLIO 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 utility classes for handling the YAML representation of
+// object files.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/YAML.h"
+
+using namespace llvm;
+
+void yaml::ScalarTraits<object::yaml::BinaryRef>::output(
+    const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
+  ArrayRef<uint8_t> Data = Val.getBinary();
+  for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
+       ++I) {
+    uint8_t Byte = *I;
+    Out << hexdigit(Byte >> 4);
+    Out << hexdigit(Byte & 0xf);
+  }
+}
+
+StringRef yaml::ScalarTraits<object::yaml::BinaryRef>::input(
+    StringRef Scalar, void *, object::yaml::BinaryRef &Val) {
+  Val = object::yaml::BinaryRef(Scalar);
+  return StringRef();
+}

Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=183287&r1=183286&r2=183287&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Tue Jun  4 21:32:26 2013
@@ -64,7 +64,7 @@ void COFFDumper::dumpSections(unsigned N
 
     ArrayRef<uint8_t> sectionData;
     Obj.getSectionContents(Sect, sectionData);
-    Sec.SectionData = COFFYAML::BinaryRef(sectionData);
+    Sec.SectionData = object::yaml::BinaryRef(sectionData);
 
     std::vector<COFF::relocation> Relocations;
     for (object::relocation_iterator rIter = iter->begin_relocations();
@@ -96,7 +96,7 @@ void COFFDumper::dumpSymbols(unsigned Nu
     Sym.Header.Value = Symbol->Value;
     Sym.Header.SectionNumber = Symbol->SectionNumber;
     Sym.Header.NumberOfAuxSymbols = Symbol->NumberOfAuxSymbols;
-    Sym.AuxiliaryData = COFFYAML::BinaryRef(Obj.getSymbolAuxData(Symbol));
+    Sym.AuxiliaryData = object::yaml::BinaryRef(Obj.getSymbolAuxData(Symbol));
     Symbols.push_back(Sym);
   }
 }





More information about the llvm-commits mailing list