Skip to content

Commit

Permalink
Invert the MC -> Object dependency.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212248 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Jul 3, 2014
1 parent af457ab commit 7413fef
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 5 additions & 28 deletions include/llvm/Object/YAML.h → include/llvm/MC/YAML.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<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
4 changes: 2 additions & 2 deletions include/llvm/Object/COFFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Object/ELFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/MC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ subdirectories = MCAnalysis MCDisassembler MCParser
type = Library
name = MC
parent = Libraries
required_libraries = Object Support
required_libraries = Support
4 changes: 2 additions & 2 deletions lib/MC/MCAnalysis/MCModuleYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -102,7 +102,7 @@ struct Atom {
uint64_t Size;

std::vector<Inst> Insts;
object::yaml::BinaryRef Data;
yaml::BinaryRef Data;
};

struct BasicBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/MC/StringTableBuilder.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Object/StringTableBuilder.h"

using namespace llvm;

Expand Down
17 changes: 8 additions & 9 deletions lib/Object/YAML.cpp → lib/MC/YAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
//
//===----------------------------------------------------------------------===//

#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?
// (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);
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;
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions lib/Object/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ add_llvm_library(LLVMObject
MachOUniversal.cpp
Object.cpp
ObjectFile.cpp
StringTableBuilder.cpp
SymbolicFile.cpp
YAML.cpp
)
2 changes: 1 addition & 1 deletion lib/Object/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
type = Library
name = Object
parent = Libraries
required_libraries = BitReader Core Support
required_libraries = BitReader Core Support MC
2 changes: 1 addition & 1 deletion tools/obj2yaml/coff2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void COFFDumper::dumpSections(unsigned NumSections) {

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()) {
Expand Down
2 changes: 1 addition & 1 deletion tools/obj2yaml/elf2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
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();
Expand Down
2 changes: 1 addition & 1 deletion tools/yaml2obj/yaml2elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions unittests/MC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set(LLVM_LINK_COMPONENTS

add_llvm_unittest(MCTests
MCAtomTest.cpp
StringTableBuilderTest.cpp
YAMLTest.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/MC/StringTableBuilder.h"
#include "gtest/gtest.h"
#include "llvm/Object/StringTableBuilder.h"
#include <string>

using namespace llvm;
Expand Down
4 changes: 2 additions & 2 deletions unittests/Object/YAMLTest.cpp → unittests/MC/YAMLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion unittests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions unittests/Object/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions unittests/Object/Makefile

This file was deleted.

0 comments on commit 7413fef

Please sign in to comment.