[llvm] r212248 - Invert the MC -> Object dependency.

Rafael Espindola rafael.espindola at gmail.com
Wed Jul 2 19:01:40 PDT 2014


Author: rafael
Date: Wed Jul  2 21:01:39 2014
New Revision: 212248

URL: http://llvm.org/viewvc/llvm-project?rev=212248&view=rev
Log:
Invert the MC -> Object dependency.

Now that we have a lib/MC/MCAnalysis, the dependency was there just because
of two helper classes. Move the two over to MC.

This will allow IRObjectFile to parse inline assembly.

Added:
    llvm/trunk/include/llvm/MC/StringTableBuilder.h
      - copied, changed from r212245, llvm/trunk/include/llvm/Object/StringTableBuilder.h
    llvm/trunk/include/llvm/MC/YAML.h
      - copied, changed from r212245, llvm/trunk/include/llvm/Object/YAML.h
    llvm/trunk/lib/MC/StringTableBuilder.cpp
      - copied, changed from r212245, llvm/trunk/lib/Object/StringTableBuilder.cpp
    llvm/trunk/lib/MC/YAML.cpp
      - copied, changed from r212245, llvm/trunk/lib/Object/YAML.cpp
    llvm/trunk/unittests/MC/StringTableBuilderTest.cpp
      - copied, changed from r212245, llvm/trunk/unittests/Object/StringTableBuilderTest.cpp
    llvm/trunk/unittests/MC/YAMLTest.cpp
      - copied, changed from r212245, llvm/trunk/unittests/Object/YAMLTest.cpp
Removed:
    llvm/trunk/include/llvm/Object/StringTableBuilder.h
    llvm/trunk/include/llvm/Object/YAML.h
    llvm/trunk/lib/Object/StringTableBuilder.cpp
    llvm/trunk/lib/Object/YAML.cpp
    llvm/trunk/unittests/Object/CMakeLists.txt
    llvm/trunk/unittests/Object/Makefile
    llvm/trunk/unittests/Object/StringTableBuilderTest.cpp
    llvm/trunk/unittests/Object/YAMLTest.cpp
Modified:
    llvm/trunk/include/llvm/Object/COFFYAML.h
    llvm/trunk/include/llvm/Object/ELFYAML.h
    llvm/trunk/lib/MC/CMakeLists.txt
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/lib/MC/LLVMBuild.txt
    llvm/trunk/lib/MC/MCAnalysis/MCModuleYAML.cpp
    llvm/trunk/lib/Object/CMakeLists.txt
    llvm/trunk/lib/Object/LLVMBuild.txt
    llvm/trunk/tools/obj2yaml/coff2yaml.cpp
    llvm/trunk/tools/obj2yaml/elf2yaml.cpp
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp
    llvm/trunk/unittests/CMakeLists.txt
    llvm/trunk/unittests/MC/CMakeLists.txt
    llvm/trunk/unittests/Makefile

Copied: llvm/trunk/include/llvm/MC/StringTableBuilder.h (from r212245, llvm/trunk/include/llvm/Object/StringTableBuilder.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/StringTableBuilder.h?p2=llvm/trunk/include/llvm/MC/StringTableBuilder.h&p1=llvm/trunk/include/llvm/Object/StringTableBuilder.h&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/StringTableBuilder.h (original)
+++ llvm/trunk/include/llvm/MC/StringTableBuilder.h Wed Jul  2 21:01:39 2014
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_OBJECT_STRINGTABLE_BUILDER_H
-#define LLVM_OBJECT_STRINGTABLE_BUILDER_H
+#ifndef LLVM_MC_STRINGTABLE_BUILDER_H
+#define LLVM_MC_STRINGTABLE_BUILDER_H
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"

Copied: llvm/trunk/include/llvm/MC/YAML.h (from r212245, llvm/trunk/include/llvm/Object/YAML.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/YAML.h?p2=llvm/trunk/include/llvm/MC/YAML.h&p1=llvm/trunk/include/llvm/Object/YAML.h&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/YAML.h (original)
+++ llvm/trunk/include/llvm/MC/YAML.h Wed Jul  2 21:01:39 2014
@@ -1,26 +1,10 @@
-//===- 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
+#ifndef LLVM_MC_YAML_H
+#define LLVM_MC_YAML_H
 
 #include "llvm/Support/YAMLTraits.h"
 
 namespace llvm {
-namespace object {
 namespace yaml {
-
 /// \brief Specialized YAMLIO scalar type for representing a binary blob.
 ///
 /// A typical use case would be to represent the content of a section in a
@@ -100,18 +84,11 @@ inline bool operator==(const BinaryRef &
   return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.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 &);
+template <> struct ScalarTraits<BinaryRef> {
+  static void output(const BinaryRef &, void *, llvm::raw_ostream &);
+  static StringRef input(StringRef, void *, BinaryRef &);
   static bool mustQuote(StringRef S) { return needsQuotes(S); }
 };
 }
-
 }
-
 #endif

Modified: llvm/trunk/include/llvm/Object/COFFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFFYAML.h?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFFYAML.h (original)
+++ llvm/trunk/include/llvm/Object/COFFYAML.h Wed Jul  2 21:01:39 2014
@@ -15,7 +15,7 @@
 #define LLVM_OBJECT_COFFYAML_H
 
 #include "llvm/ADT/Optional.h"
-#include "llvm/Object/YAML.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/Support/COFF.h"
 
 namespace llvm {
@@ -49,7 +49,7 @@ namespace COFFYAML {
   struct Section {
     COFF::section Header;
     unsigned Alignment;
-    object::yaml::BinaryRef SectionData;
+    yaml::BinaryRef SectionData;
     std::vector<Relocation> Relocations;
     StringRef Name;
     Section();

Modified: llvm/trunk/include/llvm/Object/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFYAML.h?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/Object/ELFYAML.h Wed Jul  2 21:01:39 2014
@@ -16,7 +16,7 @@
 #ifndef LLVM_OBJECT_ELFYAML_H
 #define LLVM_OBJECT_ELFYAML_H
 
-#include "llvm/Object/YAML.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/Support/ELF.h"
 
 namespace llvm {
@@ -83,7 +83,7 @@ struct Section {
   virtual ~Section();
 };
 struct RawContentSection : Section {
-  object::yaml::BinaryRef Content;
+  yaml::BinaryRef Content;
   llvm::yaml::Hex64 Size;
   RawContentSection() : Section(SectionKind::RawContent) {}
   static bool classof(const Section *S) {

Removed: llvm/trunk/include/llvm/Object/StringTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/StringTableBuilder.h?rev=212247&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Object/StringTableBuilder.h (original)
+++ llvm/trunk/include/llvm/Object/StringTableBuilder.h (removed)
@@ -1,59 +0,0 @@
-//===-- StringTableBuilder.h - String table building utility ------*- C++ -*-=//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_OBJECT_STRINGTABLE_BUILDER_H
-#define LLVM_OBJECT_STRINGTABLE_BUILDER_H
-
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringMap.h"
-#include <cassert>
-
-namespace llvm {
-
-/// \brief Utility for building string tables with deduplicated suffixes.
-class StringTableBuilder {
-  SmallString<256> StringTable;
-  StringMap<size_t> StringIndexMap;
-
-public:
-  /// \brief Add a string to the builder. Returns a StringRef to the internal
-  /// copy of s. Can only be used before the table is finalized.
-  StringRef add(StringRef s) {
-    assert(!isFinalized());
-    return StringIndexMap.GetOrCreateValue(s, 0).getKey();
-  }
-
-  /// \brief Analyze the strings and build the final table. No more strings can
-  /// be added after this point.
-  void finalize();
-
-  /// \brief Retrieve the string table data. Can only be used after the table
-  /// is finalized.
-  StringRef data() {
-    assert(isFinalized());
-    return StringTable;
-  }
-
-  /// \brief Get the offest of a string in the string table. Can only be used
-  /// after the table is finalized.
-  size_t getOffset(StringRef s) {
-    assert(isFinalized());
-    assert(StringIndexMap.count(s) && "String is not in table!");
-    return StringIndexMap[s];
-  }
-
-private:
-  bool isFinalized() {
-    return !StringTable.empty();
-  }
-};
-
-} // end llvm namespace
-
-#endif

Removed: llvm/trunk/include/llvm/Object/YAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/YAML.h?rev=212247&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Object/YAML.h (original)
+++ llvm/trunk/include/llvm/Object/YAML.h (removed)
@@ -1,117 +0,0 @@
-//===- 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 {
-
-/// \brief Specialized YAMLIO scalar type for representing a binary blob.
-///
-/// A typical use case would be to represent the content of a section in a
-/// binary file.
-/// This class has custom YAMLIO traits for convenient reading and writing.
-/// It renders as a string of hex digits in a YAML file.
-/// For example, it might render as `DEADBEEFCAFEBABE` (YAML does not
-/// require the quotation marks, so for simplicity when outputting they are
-/// omitted).
-/// When reading, any string whose content is an even number of hex digits
-/// will be accepted.
-/// For example, all of the following are acceptable:
-/// `DEADBEEF`, `"DeADbEeF"`, `"\x44EADBEEF"` (Note: '\x44' == 'D')
-///
-/// A significant advantage of using this class is that it never allocates
-/// temporary strings or buffers for any of its functionality.
-///
-/// Example:
-///
-/// The YAML mapping:
-/// \code
-/// Foo: DEADBEEFCAFEBABE
-/// \endcode
-///
-/// Could be modeled in YAMLIO by the struct:
-/// \code
-/// struct FooHolder {
-///   BinaryRef Foo;
-/// };
-/// namespace llvm {
-/// namespace yaml {
-/// template <>
-/// struct MappingTraits<FooHolder> {
-///   static void mapping(IO &IO, FooHolder &FH) {
-///     IO.mapRequired("Foo", FH.Foo);
-///   }
-/// };
-/// } // end namespace yaml
-/// } // end namespace llvm
-/// \endcode
-class BinaryRef {
-  friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS);
-  /// \brief Either raw binary data, or a string of hex bytes (must always
-  /// be an even number of characters).
-  ArrayRef<uint8_t> Data;
-  /// \brief Discriminator between the two states of the `Data` member.
-  bool DataIsHexString;
-
-public:
-  BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {}
-  BinaryRef(StringRef Data)
-      : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()),
-        DataIsHexString(true) {}
-  BinaryRef() : DataIsHexString(true) {}
-  /// \brief The number of bytes that are represented by this BinaryRef.
-  /// This is the number of bytes that writeAsBinary() will write.
-  ArrayRef<uint8_t>::size_type binary_size() const {
-    if (DataIsHexString)
-      return Data.size() / 2;
-    return Data.size();
-  }
-  /// \brief Write the contents (regardless of whether it is binary or a
-  /// hex string) as binary to the given raw_ostream.
-  void writeAsBinary(raw_ostream &OS) const;
-  /// \brief Write the contents (regardless of whether it is binary or a
-  /// hex string) as hex to the given raw_ostream.
-  ///
-  /// For example, a possible output could be `DEADBEEFCAFEBABE`.
-  void writeAsHex(raw_ostream &OS) const;
-};
-
-inline bool operator==(const BinaryRef &LHS, const BinaryRef &RHS) {
-  // Special case for default constructed BinaryRef.
-  if (LHS.Data.empty() && RHS.Data.empty())
-    return true;
-
-  return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.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 &);
-  static bool mustQuote(StringRef S) { return needsQuotes(S); }
-};
-}
-
-}
-
-#endif

Modified: llvm/trunk/lib/MC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/CMakeLists.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/MC/CMakeLists.txt (original)
+++ llvm/trunk/lib/MC/CMakeLists.txt Wed Jul  2 21:01:39 2014
@@ -43,9 +43,11 @@ add_llvm_library(LLVMMC
   MCValue.cpp
   MCWin64EH.cpp
   MachObjectWriter.cpp
+  StringTableBuilder.cpp
   SubtargetFeature.cpp
   WinCOFFObjectWriter.cpp
   WinCOFFStreamer.cpp
+  YAML.cpp
   )
 
 add_subdirectory(MCAnalysis)

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Jul  2 21:01:39 2014
@@ -28,7 +28,7 @@
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCValue.h"
-#include "llvm/Object/StringTableBuilder.h"
+#include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"

Modified: llvm/trunk/lib/MC/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/LLVMBuild.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/MC/LLVMBuild.txt (original)
+++ llvm/trunk/lib/MC/LLVMBuild.txt Wed Jul  2 21:01:39 2014
@@ -22,4 +22,4 @@ subdirectories = MCAnalysis MCDisassembl
 type = Library
 name = MC
 parent = Libraries
-required_libraries = Object Support
+required_libraries = Support

Modified: llvm/trunk/lib/MC/MCAnalysis/MCModuleYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAnalysis/MCModuleYAML.cpp?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAnalysis/MCModuleYAML.cpp (original)
+++ llvm/trunk/lib/MC/MCAnalysis/MCModuleYAML.cpp Wed Jul  2 21:01:39 2014
@@ -17,7 +17,7 @@
 #include "llvm/MC/MCAnalysis/MCFunction.h"
 #include "llvm/MC/MCInstrInfo.h"
 #include "llvm/MC/MCRegisterInfo.h"
-#include "llvm/Object/YAML.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/MathExtras.h"
@@ -102,7 +102,7 @@ struct Atom {
   uint64_t Size;
 
   std::vector<Inst> Insts;
-  object::yaml::BinaryRef Data;
+  yaml::BinaryRef Data;
 };
 
 struct BasicBlock {

Copied: llvm/trunk/lib/MC/StringTableBuilder.cpp (from r212245, llvm/trunk/lib/Object/StringTableBuilder.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/StringTableBuilder.cpp?p2=llvm/trunk/lib/MC/StringTableBuilder.cpp&p1=llvm/trunk/lib/Object/StringTableBuilder.cpp&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/lib/Object/StringTableBuilder.cpp (original)
+++ llvm/trunk/lib/MC/StringTableBuilder.cpp Wed Jul  2 21:01:39 2014
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/MC/StringTableBuilder.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Object/StringTableBuilder.h"
 
 using namespace llvm;
 

Copied: llvm/trunk/lib/MC/YAML.cpp (from r212245, llvm/trunk/lib/Object/YAML.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/YAML.cpp?p2=llvm/trunk/lib/MC/YAML.cpp&p1=llvm/trunk/lib/Object/YAML.cpp&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (original)
+++ llvm/trunk/lib/MC/YAML.cpp Wed Jul  2 21:01:39 2014
@@ -12,21 +12,20 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Object/YAML.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cctype>
 
 using namespace llvm;
-using namespace object::yaml;
 
-void yaml::ScalarTraits<object::yaml::BinaryRef>::output(
-    const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
+void yaml::ScalarTraits<yaml::BinaryRef>::output(
+    const yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
   Val.writeAsHex(Out);
 }
 
-StringRef yaml::ScalarTraits<object::yaml::BinaryRef>::input(
-    StringRef Scalar, void *, object::yaml::BinaryRef &Val) {
+StringRef yaml::ScalarTraits<yaml::BinaryRef>::input(StringRef Scalar, void *,
+                                                     yaml::BinaryRef &Val) {
   if (Scalar.size() % 2 != 0)
     return "BinaryRef hex string must contain an even number of nybbles.";
   // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
@@ -34,11 +33,11 @@ StringRef yaml::ScalarTraits<object::yam
   for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
     if (!isxdigit(Scalar[I]))
       return "BinaryRef hex string must contain only hex digits.";
-  Val = object::yaml::BinaryRef(Scalar);
+  Val = yaml::BinaryRef(Scalar);
   return StringRef();
 }
 
-void BinaryRef::writeAsBinary(raw_ostream &OS) const {
+void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {
   if (!DataIsHexString) {
     OS.write((const char *)Data.data(), Data.size());
     return;
@@ -50,7 +49,7 @@ void BinaryRef::writeAsBinary(raw_ostrea
   }
 }
 
-void BinaryRef::writeAsHex(raw_ostream &OS) const {
+void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const {
   if (binary_size() == 0)
     return;
   if (DataIsHexString) {

Modified: llvm/trunk/lib/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/CMakeLists.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/Object/CMakeLists.txt (original)
+++ llvm/trunk/lib/Object/CMakeLists.txt Wed Jul  2 21:01:39 2014
@@ -12,7 +12,5 @@ add_llvm_library(LLVMObject
   MachOUniversal.cpp
   Object.cpp
   ObjectFile.cpp
-  StringTableBuilder.cpp
   SymbolicFile.cpp
-  YAML.cpp
   )

Modified: llvm/trunk/lib/Object/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/LLVMBuild.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/lib/Object/LLVMBuild.txt (original)
+++ llvm/trunk/lib/Object/LLVMBuild.txt Wed Jul  2 21:01:39 2014
@@ -19,4 +19,4 @@
 type = Library
 name = Object
 parent = Libraries
-required_libraries = BitReader Core Support
+required_libraries = BitReader Core Support MC

Removed: llvm/trunk/lib/Object/StringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/StringTableBuilder.cpp?rev=212247&view=auto
==============================================================================
--- llvm/trunk/lib/Object/StringTableBuilder.cpp (original)
+++ llvm/trunk/lib/Object/StringTableBuilder.cpp (removed)
@@ -1,51 +0,0 @@
-//===-- StringTableBuilder.cpp - String table building utility ------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Object/StringTableBuilder.h"
-
-using namespace llvm;
-
-static bool compareBySuffix(StringRef a, StringRef b) {
-  size_t sizeA = a.size();
-  size_t sizeB = b.size();
-  size_t len = std::min(sizeA, sizeB);
-  for (size_t i = 0; i < len; ++i) {
-    char ca = a[sizeA - i - 1];
-    char cb = b[sizeB - i - 1];
-    if (ca != cb)
-      return ca > cb;
-  }
-  return sizeA > sizeB;
-}
-
-void StringTableBuilder::finalize() {
-  SmallVector<StringRef, 8> Strings;
-  for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i)
-    Strings.push_back(i->getKey());
-
-  std::sort(Strings.begin(), Strings.end(), compareBySuffix);
-
-  // FIXME: Starting with a null byte is ELF specific. Generalize this so we
-  // can use the class with other object formats.
-  StringTable += '\x00';
-
-  StringRef Previous;
-  for (StringRef s : Strings) {
-    if (Previous.endswith(s)) {
-      StringIndexMap[s] = StringTable.size() - 1 - s.size();
-      continue;
-    }
-
-    StringIndexMap[s] = StringTable.size();
-    StringTable += s;
-    StringTable += '\x00';
-    Previous = s;
-  }
-}

Removed: llvm/trunk/lib/Object/YAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/YAML.cpp?rev=212247&view=auto
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (original)
+++ llvm/trunk/lib/Object/YAML.cpp (removed)
@@ -1,66 +0,0 @@
-//===- 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"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cctype>
-
-using namespace llvm;
-using namespace object::yaml;
-
-void yaml::ScalarTraits<object::yaml::BinaryRef>::output(
-    const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
-  Val.writeAsHex(Out);
-}
-
-StringRef yaml::ScalarTraits<object::yaml::BinaryRef>::input(
-    StringRef Scalar, void *, object::yaml::BinaryRef &Val) {
-  if (Scalar.size() % 2 != 0)
-    return "BinaryRef hex string must contain an even number of nybbles.";
-  // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
-  // (e.g. a caret pointing to the offending character).
-  for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
-    if (!isxdigit(Scalar[I]))
-      return "BinaryRef hex string must contain only hex digits.";
-  Val = object::yaml::BinaryRef(Scalar);
-  return StringRef();
-}
-
-void BinaryRef::writeAsBinary(raw_ostream &OS) const {
-  if (!DataIsHexString) {
-    OS.write((const char *)Data.data(), Data.size());
-    return;
-  }
-  for (unsigned I = 0, N = Data.size(); I != N; I += 2) {
-    uint8_t Byte;
-    StringRef((const char *)&Data[I],  2).getAsInteger(16, Byte);
-    OS.write(Byte);
-  }
-}
-
-void BinaryRef::writeAsHex(raw_ostream &OS) const {
-  if (binary_size() == 0)
-    return;
-  if (DataIsHexString) {
-    OS.write((const char *)Data.data(), Data.size());
-    return;
-  }
-  for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
-       ++I) {
-    uint8_t Byte = *I;
-    OS << hexdigit(Byte >> 4);
-    OS << hexdigit(Byte & 0xf);
-  }
-}

Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Wed Jul  2 21:01:39 2014
@@ -61,7 +61,7 @@ void COFFDumper::dumpSections(unsigned N
 
     ArrayRef<uint8_t> sectionData;
     Obj.getSectionContents(Sect, sectionData);
-    Sec.SectionData = object::yaml::BinaryRef(sectionData);
+    Sec.SectionData = yaml::BinaryRef(sectionData);
 
     std::vector<COFFYAML::Relocation> Relocations;
     for (const auto &Reloc : Section.relocations()) {

Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Wed Jul  2 21:01:39 2014
@@ -268,7 +268,7 @@ ELFDumper<ELFT>::dumpContentSection(cons
   ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr);
   if (std::error_code EC = ContentOrErr.getError())
     return EC;
-  S->Content = object::yaml::BinaryRef(ContentOrErr.get());
+  S->Content = yaml::BinaryRef(ContentOrErr.get());
   S->Size = S->Content.binary_size();
 
   return S.release();

Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Wed Jul  2 21:01:39 2014
@@ -14,9 +14,9 @@
 
 #include "yaml2obj.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/ELFYAML.h"
-#include "llvm/Object/StringTableBuilder.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"

Modified: llvm/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CMakeLists.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/unittests/CMakeLists.txt (original)
+++ llvm/trunk/unittests/CMakeLists.txt Wed Jul  2 21:01:39 2014
@@ -21,7 +21,6 @@ add_subdirectory(IR)
 add_subdirectory(LineEditor)
 add_subdirectory(Linker)
 add_subdirectory(MC)
-add_subdirectory(Object)
 add_subdirectory(Option)
 add_subdirectory(Support)
 add_subdirectory(Transforms)

Modified: llvm/trunk/unittests/MC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MC/CMakeLists.txt?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/unittests/MC/CMakeLists.txt (original)
+++ llvm/trunk/unittests/MC/CMakeLists.txt Wed Jul  2 21:01:39 2014
@@ -4,4 +4,6 @@ set(LLVM_LINK_COMPONENTS
 
 add_llvm_unittest(MCTests
   MCAtomTest.cpp
+  StringTableBuilderTest.cpp
+  YAMLTest.cpp
   )

Copied: llvm/trunk/unittests/MC/StringTableBuilderTest.cpp (from r212245, llvm/trunk/unittests/Object/StringTableBuilderTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MC/StringTableBuilderTest.cpp?p2=llvm/trunk/unittests/MC/StringTableBuilderTest.cpp&p1=llvm/trunk/unittests/Object/StringTableBuilderTest.cpp&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/unittests/Object/StringTableBuilderTest.cpp (original)
+++ llvm/trunk/unittests/MC/StringTableBuilderTest.cpp Wed Jul  2 21:01:39 2014
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/MC/StringTableBuilder.h"
 #include "gtest/gtest.h"
-#include "llvm/Object/StringTableBuilder.h"
 #include <string>
 
 using namespace llvm;

Copied: llvm/trunk/unittests/MC/YAMLTest.cpp (from r212245, llvm/trunk/unittests/Object/YAMLTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MC/YAMLTest.cpp?p2=llvm/trunk/unittests/MC/YAMLTest.cpp&p1=llvm/trunk/unittests/Object/YAMLTest.cpp&r1=212245&r2=212248&rev=212248&view=diff
==============================================================================
--- llvm/trunk/unittests/Object/YAMLTest.cpp (original)
+++ llvm/trunk/unittests/MC/YAMLTest.cpp Wed Jul  2 21:01:39 2014
@@ -7,14 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Object/YAML.h"
+#include "llvm/MC/YAML.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
 
 struct BinaryHolder {
-  object::yaml::BinaryRef Binary;
+  yaml::BinaryRef Binary;
 };
 
 namespace llvm {

Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=212248&r1=212247&r2=212248&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Wed Jul  2 21:01:39 2014
@@ -10,7 +10,7 @@
 LEVEL = ..
 
 PARALLEL_DIRS = ADT Analysis Bitcode CodeGen DebugInfo ExecutionEngine IR \
-		LineEditor Linker MC Object Option Support Transforms
+		LineEditor Linker MC Option Support Transforms
 
 include $(LEVEL)/Makefile.config
 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest

Removed: llvm/trunk/unittests/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/CMakeLists.txt?rev=212247&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Object/CMakeLists.txt (removed)
@@ -1,9 +0,0 @@
-set(LLVM_LINK_COMPONENTS
-  Object
-  Support
-  )
-
-add_llvm_unittest(ObjectTests
-  StringTableBuilderTest.cpp
-  YAMLTest.cpp
-  )

Removed: llvm/trunk/unittests/Object/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/Makefile?rev=212247&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/Makefile (original)
+++ llvm/trunk/unittests/Object/Makefile (removed)
@@ -1,15 +0,0 @@
-##===- unittests/Object/Makefile ---------------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../..
-TESTNAME = Object
-LINK_COMPONENTS := object
-
-include $(LEVEL)/Makefile.config
-include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest

Removed: llvm/trunk/unittests/Object/StringTableBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/StringTableBuilderTest.cpp?rev=212247&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/StringTableBuilderTest.cpp (original)
+++ llvm/trunk/unittests/Object/StringTableBuilderTest.cpp (removed)
@@ -1,40 +0,0 @@
-//===----------- StringTableBuilderTest.cpp -------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "llvm/Object/StringTableBuilder.h"
-#include <string>
-
-using namespace llvm;
-
-namespace {
-
-TEST(StringTableBuilderTest, Basic) {
-  StringTableBuilder B;
-
-  B.add("foo");
-  B.add("bar");
-  B.add("foobar");
-
-  B.finalize();
-
-  std::string Expected;
-  Expected += '\x00';
-  Expected += "foobar";
-  Expected += '\x00';
-  Expected += "foo";
-  Expected += '\x00';
-
-  EXPECT_EQ(Expected, B.data());
-  EXPECT_EQ(1U, B.getOffset("foobar"));
-  EXPECT_EQ(4U, B.getOffset("bar"));
-  EXPECT_EQ(8U, B.getOffset("foo"));
-}
-
-}

Removed: llvm/trunk/unittests/Object/YAMLTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/YAMLTest.cpp?rev=212247&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/YAMLTest.cpp (original)
+++ llvm/trunk/unittests/Object/YAMLTest.cpp (removed)
@@ -1,38 +0,0 @@
-//===- llvm/unittest/Object/YAMLTest.cpp - Tests for Object YAML ----------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Object/YAML.h"
-#include "llvm/Support/YAMLTraits.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-struct BinaryHolder {
-  object::yaml::BinaryRef Binary;
-};
-
-namespace llvm {
-namespace yaml {
-template <>
-struct MappingTraits<BinaryHolder> {
-  static void mapping(IO &IO, BinaryHolder &BH) {
-    IO.mapRequired("Binary", BH.Binary);
-  }
-};
-} // end namespace yaml
-} // end namespace llvm
-
-TEST(ObjectYAML, BinaryRef) {
-  BinaryHolder BH;
-  SmallVector<char, 32> Buf;
-  llvm::raw_svector_ostream OS(Buf);
-  yaml::Output YOut(OS);
-  YOut << BH;
-  EXPECT_NE(OS.str().find("''"), StringRef::npos);
-}





More information about the llvm-commits mailing list