forked from OSchip/llvm-project
ELF: Simplify CreateELF.
CreateELF was a combination of templates and C preprocessor macros. This patch removes uses of macros. http://reviews.llvm.org/D8810 llvm-svn: 234253
This commit is contained in:
parent
8b4956a507
commit
7c869e4821
|
@ -18,10 +18,9 @@
|
|||
|
||||
#include "lld/Core/File.h"
|
||||
#include "llvm/Object/ELF.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
|
||||
namespace {
|
||||
using llvm::object::ELFType;
|
||||
|
||||
/// \func createELF
|
||||
/// \brief Create an object depending on the runtime attributes and alignment
|
||||
|
@ -34,43 +33,27 @@ using llvm::object::ELFType;
|
|||
/// \param ident pair of EI_CLASS and EI_DATA.
|
||||
/// \param maxAlignment the maximum alignment of the file.
|
||||
/// \param args arguments forwarded to CreateELFTraits<T>::create.
|
||||
|
||||
#define LLVM_CREATE_ELF_CreateELFTraits(endian, align, is64, ...) \
|
||||
new FileT<ELFType<llvm::support::endian, align, is64>>(__VA_ARGS__);
|
||||
|
||||
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||
# define LLVM_CREATE_ELF_Create(normal, low, endian, is64, ...) \
|
||||
if (maxAlignment >= normal) \
|
||||
return LLVM_CREATE_ELF_CreateELFTraits(endian, normal, is64, __VA_ARGS__) \
|
||||
else if (maxAlignment >= low) \
|
||||
return LLVM_CREATE_ELF_CreateELFTraits(endian, low, is64, __VA_ARGS__) \
|
||||
else \
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
#else
|
||||
# define LLVM_CREATE_ELF_Create(normal, low, endian, is64, ...) \
|
||||
if (maxAlignment >= low) \
|
||||
file = LLVM_CREATE_ELF_CreateELFTraits(endian, low, is64, __VA_ARGS__) \
|
||||
else \
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
#endif
|
||||
|
||||
template <template <typename ELFT> class FileT, class... Args>
|
||||
llvm::ErrorOr<std::unique_ptr<lld::File>>
|
||||
createELF(std::pair<unsigned char, unsigned char> ident,
|
||||
std::size_t maxAlignment, Args &&... args) {
|
||||
using namespace llvm::ELF;
|
||||
using namespace llvm::support;
|
||||
using llvm::object::ELFType;
|
||||
if (maxAlignment < 2)
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
|
||||
lld::File *file = nullptr;
|
||||
if (ident.first == llvm::ELF::ELFCLASS32 &&
|
||||
ident.second == llvm::ELF::ELFDATA2LSB) {
|
||||
LLVM_CREATE_ELF_Create(4, 2, little, false, std::forward<Args>(args)...)
|
||||
} else if (ident.first == llvm::ELF::ELFCLASS32 &&
|
||||
ident.second == llvm::ELF::ELFDATA2MSB) {
|
||||
LLVM_CREATE_ELF_Create(4, 2, big, false, std::forward<Args>(args)...)
|
||||
} else if (ident.first == llvm::ELF::ELFCLASS64 &&
|
||||
ident.second == llvm::ELF::ELFDATA2MSB) {
|
||||
LLVM_CREATE_ELF_Create(8, 2, big, true, std::forward<Args>(args)...)
|
||||
} else if (ident.first == llvm::ELF::ELFCLASS64 &&
|
||||
ident.second == llvm::ELF::ELFDATA2LSB) {
|
||||
LLVM_CREATE_ELF_Create(8, 2, little, true, std::forward<Args>(args)...)
|
||||
unsigned char size = ident.first;
|
||||
unsigned char endian = ident.second;
|
||||
if (size == ELFCLASS32 && endian == ELFDATA2LSB) {
|
||||
file = new FileT<ELFType<little, 2, false>>(std::forward<Args>(args)...);
|
||||
} else if (size == ELFCLASS32 && endian == ELFDATA2MSB) {
|
||||
file = new FileT<ELFType<big, 2, false>>(std::forward<Args>(args)...);
|
||||
} else if (size == ELFCLASS64 && endian == ELFDATA2LSB) {
|
||||
file = new FileT<ELFType<little, 2, true>>(std::forward<Args>(args)...);
|
||||
} else if (size == ELFCLASS64 && endian == ELFDATA2MSB) {
|
||||
file = new FileT<ELFType<big, 2, true>>(std::forward<Args>(args)...);
|
||||
}
|
||||
if (!file)
|
||||
llvm_unreachable("Invalid ELF type!");
|
||||
|
@ -79,7 +62,4 @@ createELF(std::pair<unsigned char, unsigned char> ident,
|
|||
|
||||
} // end anon namespace
|
||||
|
||||
#undef LLVM_CREATE_ELF_CreateELFTraits
|
||||
#undef LLVM_CREATE_ELF_Create
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue