[lld] r183740 - Factor duplicated yamlReader creation.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jun 11 05:36:06 PDT 2013
Author: rafael
Date: Tue Jun 11 07:36:05 2013
New Revision: 183740
URL: http://llvm.org/viewvc/llvm-project?rev=183740&view=rev
Log:
Factor duplicated yamlReader creation.
The yaml reader is not specific to any file format. This patch moves
it to TargetInfo and makes validate a non virtual interface so that it
can be constructed from a single location.
The same method will be used to create a reader for llvm bitcode
files.
Modified:
lld/trunk/include/lld/Core/TargetInfo.h
lld/trunk/include/lld/ReaderWriter/CoreTargetInfo.h
lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h
lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
lld/trunk/lib/Core/TargetInfo.cpp
lld/trunk/lib/ReaderWriter/CoreTargetInfo.cpp
lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
Modified: lld/trunk/include/lld/Core/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/TargetInfo.h?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/TargetInfo.h (original)
+++ lld/trunk/include/lld/Core/TargetInfo.h Tue Jun 11 07:36:05 2013
@@ -243,7 +243,7 @@ public:
/// is written to the supplied stream.
///
/// \returns true if there is an error with the current settings.
- virtual bool validate(raw_ostream &diagnostics) = 0;
+ bool validate(raw_ostream &diagnostics);
/// @}
@@ -339,6 +339,11 @@ protected:
std::vector<StringRef> _deadStripRoots;
std::vector<LinkerInput> _inputFiles;
std::vector<const char*> _llvmOptions;
+ std::unique_ptr<Reader> _yamlReader;
+
+ private:
+ /// Validate the subclass bits. Only called by validate.
+ virtual bool validateImpl(raw_ostream &diagnostics) = 0;
};
} // end namespace lld
Modified: lld/trunk/include/lld/ReaderWriter/CoreTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/CoreTargetInfo.h?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/CoreTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/CoreTargetInfo.h Tue Jun 11 07:36:05 2013
@@ -22,10 +22,7 @@ class CoreTargetInfo : public TargetInfo
public:
CoreTargetInfo();
- virtual bool validate(raw_ostream &diagnostics) {
- return false;
- }
-
+ virtual bool validateImpl(raw_ostream &diagnostics);
virtual void addPasses(PassManager &pm) const;
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Tue Jun 11 07:36:05 2013
@@ -62,7 +62,7 @@ public:
const Reference &) const {
return false;
}
- virtual bool validate(raw_ostream &diagnostics);
+ virtual bool validateImpl(raw_ostream &diagnostics);
virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb,
@@ -148,7 +148,6 @@ protected:
std::vector<StringRef> _inputSearchPaths;
llvm::BumpPtrAllocator _extraStrings;
std::unique_ptr<Reader> _elfReader;
- std::unique_ptr<Reader> _yamlReader;
std::unique_ptr<Writer> _writer;
std::unique_ptr<Reader> _linkerScriptReader;
StringRef _dynamicLinkerPath;
Modified: lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h Tue Jun 11 07:36:05 2013
@@ -30,8 +30,8 @@ public:
virtual void addPasses(PassManager &pm) const;
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
- virtual bool validate(raw_ostream &diagnostics);
-
+ virtual bool validateImpl(raw_ostream &diagnostics);
+
virtual error_code parseFile(std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File>> &result) const;
@@ -97,7 +97,6 @@ private:
uint64_t _pageZeroSize;
mutable std::unique_ptr<mach_o::KindHandler> _kindHandler;
mutable std::unique_ptr<Reader> _machoReader;
- mutable std::unique_ptr<Reader> _yamlReader;
mutable std::unique_ptr<Writer> _writer;
};
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h Tue Jun 11 07:36:05 2013
@@ -41,7 +41,7 @@ public:
std::vector<std::unique_ptr<File>> &result) const;
virtual Writer &writer() const;
- virtual bool validate(raw_ostream &diagnostics);
+ virtual bool validateImpl(raw_ostream &diagnostics);
virtual void addPasses(PassManager &pm) const {}
Modified: lld/trunk/lib/Core/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/TargetInfo.cpp?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/lib/Core/TargetInfo.cpp (original)
+++ lld/trunk/lib/Core/TargetInfo.cpp Tue Jun 11 07:36:05 2013
@@ -26,6 +26,11 @@ TargetInfo::TargetInfo()
TargetInfo::~TargetInfo() {}
+bool TargetInfo::validate(raw_ostream &diagnostics) {
+ _yamlReader = createReaderYAML(*this);
+ return validateImpl(diagnostics);
+}
+
error_code TargetInfo::readFile(StringRef path,
std::vector<std::unique_ptr<File>> &result) const {
OwningPtr<llvm::MemoryBuffer> opmb;
Modified: lld/trunk/lib/ReaderWriter/CoreTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/CoreTargetInfo.cpp?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/CoreTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/CoreTargetInfo.cpp Tue Jun 11 07:36:05 2013
@@ -344,6 +344,9 @@ private:
CoreTargetInfo::CoreTargetInfo() {
}
+bool CoreTargetInfo::validateImpl(raw_ostream &diagnostics) {
+ return false;
+}
void CoreTargetInfo::addPasses(PassManager &pm) const {
for (StringRef name : _passNames) {
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Tue Jun 11 07:36:05 2013
@@ -63,7 +63,7 @@ uint16_t ELFTargetInfo::getOutputMachine
}
}
-bool ELFTargetInfo::validate(raw_ostream &diagnostics) {
+bool ELFTargetInfo::validateImpl(raw_ostream &diagnostics) {
if (_outputFileType == elf::ET_EXEC &&
_entrySymbolName.empty()) {
_entrySymbolName = "_start";
@@ -75,7 +75,6 @@ bool ELFTargetInfo::validate(raw_ostream
}
_elfReader = createReaderELF(*this);
- _yamlReader = createReaderYAML(*this);
_linkerScriptReader.reset(new ReaderLinkerScript(*this));
_writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this);
return false;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp Tue Jun 11 07:36:05 2013
@@ -181,7 +181,7 @@ bool MachOTargetInfo::addUnixThreadLoadC
}
}
-bool MachOTargetInfo::validate(raw_ostream &diagnostics) {
+bool MachOTargetInfo::validateImpl(raw_ostream &diagnostics) {
if ((_outputFileType == mach_o::MH_EXECUTE) && _entrySymbolName.empty()) {
if (_outputFileTypeStatic) {
_entrySymbolName = "start";
@@ -217,8 +217,6 @@ error_code MachOTargetInfo::parseFile(st
// _machoReader = createReaderMachO(*this);
// error_code ec = _machoReader->parseFile(mb,result);
// if (ec) {
- if (!_yamlReader)
- _yamlReader = createReaderYAML(*this);
return _yamlReader->parseFile(mb, result);
// }
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp?rev=183740&r1=183739&r2=183740&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp Tue Jun 11 07:36:05 2013
@@ -22,7 +22,7 @@ error_code PECOFFTargetInfo::parseFile(
return _reader->parseFile(mb, result);
}
-bool PECOFFTargetInfo::validate(raw_ostream &diagnostics) {
+bool PECOFFTargetInfo::validateImpl(raw_ostream &diagnostics) {
if (_stackReserve < _stackCommit) {
diagnostics << "Invalid stack size: reserve size must be equal to or "
<< "greater than commit size, but got "
More information about the llvm-commits
mailing list