[lld] r234253 - ELF: Simplify CreateELF.
Rui Ueyama
ruiu at google.com
Mon Apr 6 16:02:48 PDT 2015
Author: ruiu
Date: Mon Apr 6 18:02:47 2015
New Revision: 234253
URL: http://llvm.org/viewvc/llvm-project?rev=234253&view=rev
Log:
ELF: Simplify CreateELF.
CreateELF was a combination of templates and C preprocessor macros.
This patch removes uses of macros.
http://reviews.llvm.org/D8810
Modified:
lld/trunk/lib/ReaderWriter/ELF/CreateELF.h
Modified: lld/trunk/lib/ReaderWriter/ELF/CreateELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CreateELF.h?rev=234253&r1=234252&r2=234253&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CreateELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CreateELF.h Mon Apr 6 18:02:47 2015
@@ -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, unsig
} // end anon namespace
-#undef LLVM_CREATE_ELF_CreateELFTraits
-#undef LLVM_CREATE_ELF_Create
-
#endif
More information about the llvm-commits
mailing list