diff options
Diffstat (limited to 'lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h')
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h new file mode 100644 index 00000000000..3585996683d --- /dev/null +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h @@ -0,0 +1,84 @@ +//===- lib/ReaderWriter/ELF/HexagonELFReader.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_HEXAGON_ELF_READER_H +#define LLD_READER_WRITER_HEXAGON_ELF_READER_H + +#include "ELFReader.h" +#include "HexagonELFFile.h" + +namespace lld { +namespace elf { + +struct HexagonDynamicFileCreateELFTraits { + typedef llvm::ErrorOr<std::unique_ptr<lld::SharedLibraryFile>> result_type; + + template <class ELFT> + static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb, + bool useUndefines) { + return lld::elf::HexagonDynamicFile<ELFT>::create(std::move(mb), + useUndefines); + } +}; + +struct HexagonELFFileCreateELFTraits { + typedef llvm::ErrorOr<std::unique_ptr<lld::File>> result_type; + + template <class ELFT> + static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb, + bool atomizeStrings) { + return lld::elf::HexagonELFFile<ELFT>::create(std::move(mb), + atomizeStrings); + } +}; + +class HexagonELFObjectReader : public ELFObjectReader { +public: + HexagonELFObjectReader(bool atomizeStrings) + : ELFObjectReader(atomizeStrings) {} + + virtual error_code + parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, + std::vector<std::unique_ptr<File>> &result) const { + std::size_t maxAlignment = + 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); + auto f = createELF<HexagonELFFileCreateELFTraits>( + llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), + _atomizeStrings); + if (error_code ec = f.getError()) + return ec; + result.push_back(std::move(*f)); + return error_code::success(); + } +}; + +class HexagonELFDSOReader : public ELFDSOReader { +public: + HexagonELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {} + + virtual error_code + parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, + std::vector<std::unique_ptr<File>> &result) const { + std::size_t maxAlignment = + 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart())); + auto f = createELF<HexagonDynamicFileCreateELFTraits>( + llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), + _useUndefines); + if (error_code ec = f.getError()) + return ec; + result.push_back(std::move(*f)); + return error_code::success(); + } +}; + +} // namespace elf +} // namespace lld + +#endif // LLD_READER_WRITER_ELF_READER_H |

