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.

llvm-svn: 183740
This commit is contained in:
Rafael Espindola 2013-06-11 12:36:05 +00:00
parent c00dd83583
commit c1b32686fe
10 changed files with 22 additions and 17 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;
};

View File

@ -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 {}

View File

@ -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;

View File

@ -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) {

View File

@ -63,7 +63,7 @@ uint16_t ELFTargetInfo::getOutputMachine() const {
}
}
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 &diagnostics) {
}
_elfReader = createReaderELF(*this);
_yamlReader = createReaderYAML(*this);
_linkerScriptReader.reset(new ReaderLinkerScript(*this));
_writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this);
return false;

View File

@ -181,7 +181,7 @@ bool MachOTargetInfo::addUnixThreadLoadCommand() const {
}
}
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(std::unique_ptr<MemoryBuffer> &mb,
// _machoReader = createReaderMachO(*this);
// error_code ec = _machoReader->parseFile(mb,result);
// if (ec) {
if (!_yamlReader)
_yamlReader = createReaderYAML(*this);
return _yamlReader->parseFile(mb, result);
// }

View File

@ -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 "