From 90be969cdb223c4d09775bc3a2114bb3339b5a2a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Jul 2014 02:01:39 +0000 Subject: [PATCH] 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. llvm-svn: 212248 --- .../llvm/{Object => MC}/StringTableBuilder.h | 4 +-- include/llvm/{Object => MC}/YAML.h | 33 +++---------------- include/llvm/Object/COFFYAML.h | 4 +-- include/llvm/Object/ELFYAML.h | 4 +-- lib/MC/CMakeLists.txt | 2 ++ lib/MC/ELFObjectWriter.cpp | 2 +- lib/MC/LLVMBuild.txt | 2 +- lib/MC/MCAnalysis/MCModuleYAML.cpp | 4 +-- lib/{Object => MC}/StringTableBuilder.cpp | 2 +- lib/{Object => MC}/YAML.cpp | 17 +++++----- lib/Object/CMakeLists.txt | 2 -- lib/Object/LLVMBuild.txt | 2 +- tools/obj2yaml/coff2yaml.cpp | 2 +- tools/obj2yaml/elf2yaml.cpp | 2 +- tools/yaml2obj/yaml2elf.cpp | 2 +- unittests/CMakeLists.txt | 1 - unittests/MC/CMakeLists.txt | 2 ++ .../{Object => MC}/StringTableBuilderTest.cpp | 2 +- unittests/{Object => MC}/YAMLTest.cpp | 4 +-- unittests/Makefile | 2 +- unittests/Object/CMakeLists.txt | 9 ----- unittests/Object/Makefile | 15 --------- 22 files changed, 36 insertions(+), 83 deletions(-) rename include/llvm/{Object => MC}/StringTableBuilder.h (94%) rename include/llvm/{Object => MC}/YAML.h (77%) rename lib/{Object => MC}/StringTableBuilder.cpp (96%) rename lib/{Object => MC}/YAML.cpp (78%) rename unittests/{Object => MC}/StringTableBuilderTest.cpp (95%) rename unittests/{Object => MC}/YAMLTest.cpp (93%) delete mode 100644 unittests/Object/CMakeLists.txt delete mode 100644 unittests/Object/Makefile diff --git a/include/llvm/Object/StringTableBuilder.h b/include/llvm/MC/StringTableBuilder.h similarity index 94% rename from include/llvm/Object/StringTableBuilder.h rename to include/llvm/MC/StringTableBuilder.h index c61e216bdf9..065e9e06e2c 100644 --- a/include/llvm/Object/StringTableBuilder.h +++ b/include/llvm/MC/StringTableBuilder.h @@ -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" diff --git a/include/llvm/Object/YAML.h b/include/llvm/MC/YAML.h similarity index 77% rename from include/llvm/Object/YAML.h rename to include/llvm/MC/YAML.h index 1792e8b6267..383cdc6785f 100644 --- a/include/llvm/Object/YAML.h +++ b/include/llvm/MC/YAML.h @@ -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 &LHS, const BinaryRef &RHS) { return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.Data; } -} -} - -namespace yaml { -template <> struct ScalarTraits { - static void output(const object::yaml::BinaryRef &, void *, - llvm::raw_ostream &); - static StringRef input(StringRef, void *, object::yaml::BinaryRef &); +template <> struct ScalarTraits { + static void output(const BinaryRef &, void *, llvm::raw_ostream &); + static StringRef input(StringRef, void *, BinaryRef &); static bool mustQuote(StringRef S) { return needsQuotes(S); } }; } - } - #endif diff --git a/include/llvm/Object/COFFYAML.h b/include/llvm/Object/COFFYAML.h index 3f48e07f575..4aba08f75dd 100644 --- a/include/llvm/Object/COFFYAML.h +++ b/include/llvm/Object/COFFYAML.h @@ -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 Relocations; StringRef Name; Section(); diff --git a/include/llvm/Object/ELFYAML.h b/include/llvm/Object/ELFYAML.h index 42eeb0ef752..fc8cc958165 100644 --- a/include/llvm/Object/ELFYAML.h +++ b/include/llvm/Object/ELFYAML.h @@ -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) { diff --git a/lib/MC/CMakeLists.txt b/lib/MC/CMakeLists.txt index f62894cab39..330519ece00 100644 --- a/lib/MC/CMakeLists.txt +++ b/lib/MC/CMakeLists.txt @@ -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) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 87f6ec0f3d1..ead05351458 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -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" diff --git a/lib/MC/LLVMBuild.txt b/lib/MC/LLVMBuild.txt index da9995d6c57..3fcb50b97c6 100644 --- a/lib/MC/LLVMBuild.txt +++ b/lib/MC/LLVMBuild.txt @@ -22,4 +22,4 @@ subdirectories = MCAnalysis MCDisassembler MCParser type = Library name = MC parent = Libraries -required_libraries = Object Support +required_libraries = Support diff --git a/lib/MC/MCAnalysis/MCModuleYAML.cpp b/lib/MC/MCAnalysis/MCModuleYAML.cpp index c51c62e928d..876b06de9c9 100644 --- a/lib/MC/MCAnalysis/MCModuleYAML.cpp +++ b/lib/MC/MCAnalysis/MCModuleYAML.cpp @@ -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 Insts; - object::yaml::BinaryRef Data; + yaml::BinaryRef Data; }; struct BasicBlock { diff --git a/lib/Object/StringTableBuilder.cpp b/lib/MC/StringTableBuilder.cpp similarity index 96% rename from lib/Object/StringTableBuilder.cpp rename to lib/MC/StringTableBuilder.cpp index 9152834a296..db58ece5c86 100644 --- a/lib/Object/StringTableBuilder.cpp +++ b/lib/MC/StringTableBuilder.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/MC/StringTableBuilder.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Object/StringTableBuilder.h" using namespace llvm; diff --git a/lib/Object/YAML.cpp b/lib/MC/YAML.cpp similarity index 78% rename from lib/Object/YAML.cpp rename to lib/MC/YAML.cpp index 61e9da30395..067e91a26d3 100644 --- a/lib/Object/YAML.cpp +++ b/lib/MC/YAML.cpp @@ -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 using namespace llvm; -using namespace object::yaml; -void yaml::ScalarTraits::output( - const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) { +void yaml::ScalarTraits::output( + const yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) { Val.writeAsHex(Out); } -StringRef yaml::ScalarTraits::input( - StringRef Scalar, void *, object::yaml::BinaryRef &Val) { +StringRef yaml::ScalarTraits::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::input( 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_ostream &OS) const { } } -void BinaryRef::writeAsHex(raw_ostream &OS) const { +void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const { if (binary_size() == 0) return; if (DataIsHexString) { diff --git a/lib/Object/CMakeLists.txt b/lib/Object/CMakeLists.txt index cd8c9efe7b0..00bf1e30c21 100644 --- a/lib/Object/CMakeLists.txt +++ b/lib/Object/CMakeLists.txt @@ -12,7 +12,5 @@ add_llvm_library(LLVMObject MachOUniversal.cpp Object.cpp ObjectFile.cpp - StringTableBuilder.cpp SymbolicFile.cpp - YAML.cpp ) diff --git a/lib/Object/LLVMBuild.txt b/lib/Object/LLVMBuild.txt index 7813832ef7e..d64ac8722f5 100644 --- a/lib/Object/LLVMBuild.txt +++ b/lib/Object/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Library name = Object parent = Libraries -required_libraries = BitReader Core Support +required_libraries = BitReader Core Support MC diff --git a/tools/obj2yaml/coff2yaml.cpp b/tools/obj2yaml/coff2yaml.cpp index 48462f69fc5..fed4533a982 100644 --- a/tools/obj2yaml/coff2yaml.cpp +++ b/tools/obj2yaml/coff2yaml.cpp @@ -61,7 +61,7 @@ void COFFDumper::dumpSections(unsigned NumSections) { ArrayRef sectionData; Obj.getSectionContents(Sect, sectionData); - Sec.SectionData = object::yaml::BinaryRef(sectionData); + Sec.SectionData = yaml::BinaryRef(sectionData); std::vector Relocations; for (const auto &Reloc : Section.relocations()) { diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index c817e1526da..8b53ee770a6 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -268,7 +268,7 @@ ELFDumper::dumpContentSection(const Elf_Shdr *Shdr) { ErrorOr> 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(); diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index 467969d21d7..6eeecaedcab 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -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" diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index bbab2a12b53..65930b5e4a1 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -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) diff --git a/unittests/MC/CMakeLists.txt b/unittests/MC/CMakeLists.txt index 496056ecf59..e2beab22ff9 100644 --- a/unittests/MC/CMakeLists.txt +++ b/unittests/MC/CMakeLists.txt @@ -4,4 +4,6 @@ set(LLVM_LINK_COMPONENTS add_llvm_unittest(MCTests MCAtomTest.cpp + StringTableBuilderTest.cpp + YAMLTest.cpp ) diff --git a/unittests/Object/StringTableBuilderTest.cpp b/unittests/MC/StringTableBuilderTest.cpp similarity index 95% rename from unittests/Object/StringTableBuilderTest.cpp rename to unittests/MC/StringTableBuilderTest.cpp index 130eb4a3d73..d30dc6222d2 100644 --- a/unittests/Object/StringTableBuilderTest.cpp +++ b/unittests/MC/StringTableBuilderTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/MC/StringTableBuilder.h" #include "gtest/gtest.h" -#include "llvm/Object/StringTableBuilder.h" #include using namespace llvm; diff --git a/unittests/Object/YAMLTest.cpp b/unittests/MC/YAMLTest.cpp similarity index 93% rename from unittests/Object/YAMLTest.cpp rename to unittests/MC/YAMLTest.cpp index 1eb1113ae6b..09709ad73fc 100644 --- a/unittests/Object/YAMLTest.cpp +++ b/unittests/MC/YAMLTest.cpp @@ -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 { diff --git a/unittests/Makefile b/unittests/Makefile index 37f654065ce..603e7d58f8c 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -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 diff --git a/unittests/Object/CMakeLists.txt b/unittests/Object/CMakeLists.txt deleted file mode 100644 index 580a894362d..00000000000 --- a/unittests/Object/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(LLVM_LINK_COMPONENTS - Object - Support - ) - -add_llvm_unittest(ObjectTests - StringTableBuilderTest.cpp - YAMLTest.cpp - ) diff --git a/unittests/Object/Makefile b/unittests/Object/Makefile deleted file mode 100644 index 9062149a24d..00000000000 --- a/unittests/Object/Makefile +++ /dev/null @@ -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