[PATCH] factor duplicated yamlReader creation
Rafael Ávila de Espíndola
rafael.espindola at gmail.com
Mon Jun 10 09:52:47 PDT 2013
Hi Bigcheese,
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.
http://llvm-reviews.chandlerc.com/D944
Files:
include/lld/Core/TargetInfo.h
include/lld/ReaderWriter/CoreTargetInfo.h
include/lld/ReaderWriter/ELFTargetInfo.h
include/lld/ReaderWriter/MachOTargetInfo.h
include/lld/ReaderWriter/PECOFFTargetInfo.h
lib/Core/TargetInfo.cpp
lib/ReaderWriter/CoreTargetInfo.cpp
lib/ReaderWriter/ELF/ELFTargetInfo.cpp
lib/ReaderWriter/MachO/MachOTargetInfo.cpp
lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
Index: include/lld/Core/TargetInfo.h
===================================================================
--- include/lld/Core/TargetInfo.h
+++ include/lld/Core/TargetInfo.h
@@ -243,7 +243,7 @@
/// 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 @@
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
Index: include/lld/ReaderWriter/CoreTargetInfo.h
===================================================================
--- include/lld/ReaderWriter/CoreTargetInfo.h
+++ include/lld/ReaderWriter/CoreTargetInfo.h
@@ -22,10 +22,7 @@
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;
Index: include/lld/ReaderWriter/ELFTargetInfo.h
===================================================================
--- include/lld/ReaderWriter/ELFTargetInfo.h
+++ include/lld/ReaderWriter/ELFTargetInfo.h
@@ -62,7 +62,7 @@
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 @@
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;
Index: include/lld/ReaderWriter/MachOTargetInfo.h
===================================================================
--- include/lld/ReaderWriter/MachOTargetInfo.h
+++ include/lld/ReaderWriter/MachOTargetInfo.h
@@ -30,8 +30,8 @@
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 @@
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;
};
Index: include/lld/ReaderWriter/PECOFFTargetInfo.h
===================================================================
--- include/lld/ReaderWriter/PECOFFTargetInfo.h
+++ include/lld/ReaderWriter/PECOFFTargetInfo.h
@@ -41,7 +41,7 @@
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 {}
Index: lib/Core/TargetInfo.cpp
===================================================================
--- lib/Core/TargetInfo.cpp
+++ lib/Core/TargetInfo.cpp
@@ -26,6 +26,11 @@
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;
Index: lib/ReaderWriter/CoreTargetInfo.cpp
===================================================================
--- lib/ReaderWriter/CoreTargetInfo.cpp
+++ lib/ReaderWriter/CoreTargetInfo.cpp
@@ -344,6 +344,9 @@
CoreTargetInfo::CoreTargetInfo() {
}
+bool CoreTargetInfo::validateImpl(raw_ostream &diagnostics) {
+ return false;
+}
void CoreTargetInfo::addPasses(PassManager &pm) const {
for (StringRef name : _passNames) {
Index: lib/ReaderWriter/ELF/ELFTargetInfo.cpp
===================================================================
--- lib/ReaderWriter/ELF/ELFTargetInfo.cpp
+++ lib/ReaderWriter/ELF/ELFTargetInfo.cpp
@@ -63,7 +63,7 @@
}
}
-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 @@
}
_elfReader = createReaderELF(*this);
- _yamlReader = createReaderYAML(*this);
_linkerScriptReader.reset(new ReaderLinkerScript(*this));
_writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this);
return false;
Index: lib/ReaderWriter/MachO/MachOTargetInfo.cpp
===================================================================
--- lib/ReaderWriter/MachO/MachOTargetInfo.cpp
+++ lib/ReaderWriter/MachO/MachOTargetInfo.cpp
@@ -181,7 +181,7 @@
}
}
-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 @@
// _machoReader = createReaderMachO(*this);
// error_code ec = _machoReader->parseFile(mb,result);
// if (ec) {
- if (!_yamlReader)
- _yamlReader = createReaderYAML(*this);
return _yamlReader->parseFile(mb, result);
// }
Index: lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
+++ lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
@@ -22,7 +22,7 @@
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 "
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D944.1.patch
Type: text/x-patch
Size: 6794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130610/35e3e62a/attachment.bin>
More information about the llvm-commits
mailing list