Previously, ELFReader takes three template arguments: EFLT, LinkingContextT and FileT. FileT is itself templated. So it was a bit complicated. Maybe too much. Most architectures don't actually need to be parameterized for ELFT. For example, x86 is always ELF32LE and x86-64 is ELF64LE. However, because ELFReader requires a ELFT argument, we needed to parameterize a class even if not needed. This patch removes the parameter from the class. So now we can de-templatize such classes (I didn't do that in this patch, though). This patch also removes ContextT parameter since it didn't have to be passed as a template argument. llvm-svn: 234853
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
//===- lib/ReaderWriter/ELF/ELFReader.h -----------------------------------===//
|
|
//
|
|
// The LLVM Linker
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_READER_WRITER_ELF_READER_H
|
|
#define LLD_READER_WRITER_ELF_READER_H
|
|
|
|
#include "DynamicFile.h"
|
|
#include "ELFFile.h"
|
|
#include "lld/Core/File.h"
|
|
#include "lld/Core/Reader.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
namespace lld {
|
|
namespace elf {
|
|
|
|
template <typename FileT> class ELFReader : public Reader {
|
|
public:
|
|
ELFReader(ELFLinkingContext &ctx) : _ctx(ctx) {}
|
|
|
|
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
|
return FileT::canParse(magic);
|
|
}
|
|
|
|
std::error_code
|
|
loadFile(std::unique_ptr<MemoryBuffer> mb, const class Registry &,
|
|
std::vector<std::unique_ptr<File>> &result) const override {
|
|
if (std::error_code ec = FileT::isCompatible(*mb, _ctx))
|
|
return ec;
|
|
result.push_back(llvm::make_unique<FileT>(std::move(mb), _ctx));
|
|
return std::error_code();
|
|
}
|
|
|
|
private:
|
|
ELFLinkingContext &_ctx;
|
|
};
|
|
|
|
} // namespace elf
|
|
} // namespace lld
|
|
|
|
#endif // LLD_READER_WRITER_ELF_READER_H
|