[lld] r246823 - Add a template helper to avoid multiple switches over the ELF kind. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 17:09:43 PDT 2015
Author: rafael
Date: Thu Sep 3 19:09:43 2015
New Revision: 246823
URL: http://llvm.org/viewvc/llvm-project?rev=246823&view=rev
Log:
Add a template helper to avoid multiple switches over the ELF kind. NFC.
Modified:
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=246823&r1=246822&r2=246823&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Sep 3 19:09:43 2015
@@ -32,49 +32,39 @@ template <class ELFT> void SymbolTable::
Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic));
}
-void SymbolTable::addELFFile(ELFFileBase *File) {
+template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {
if (const ELFFileBase *Old = getFirstELF()) {
if (!Old->isCompatibleWith(*File))
error(Twine(Old->getName() + " is incompatible with " + File->getName()));
} else {
- switch (File->getELFKind()) {
+ init<ELFT>();
+ }
+
+ if (auto *O = dyn_cast<ObjectFileBase>(File)) {
+ ObjectFiles.emplace_back(O);
+ for (SymbolBody *Body : O->getSymbols())
+ resolve<ELFT>(Body);
+ }
+
+ if (auto *S = dyn_cast<SharedFileBase>(File))
+ SharedFiles.emplace_back(S);
+}
+
+void SymbolTable::addELFFile(ELFFileBase *File) {
+ switch (File->getELFKind()) {
case ELF32LEKind:
- init<ELF32LE>();
+ addELFFile<ELF32LE>(File);
break;
case ELF32BEKind:
- init<ELF32BE>();
+ addELFFile<ELF32BE>(File);
break;
case ELF64LEKind:
- init<ELF64LE>();
+ addELFFile<ELF64LE>(File);
break;
case ELF64BEKind:
- init<ELF64BE>();
+ addELFFile<ELF64BE>(File);
break;
- }
}
-
- if (auto *O = dyn_cast<ObjectFileBase>(File)) {
- ObjectFiles.emplace_back(O);
- for (SymbolBody *Body : O->getSymbols()) {
- switch (File->getELFKind()) {
- case ELF32LEKind:
- resolve<ELF32LE>(Body);
- break;
- case ELF32BEKind:
- resolve<ELF32BE>(Body);
- break;
- case ELF64LEKind:
- resolve<ELF64LE>(Body);
- break;
- case ELF64BEKind:
- resolve<ELF64BE>(Body);
- break;
- }
- }
- }
-
- if (auto *S = dyn_cast<SharedFileBase>(File))
- SharedFiles.emplace_back(S);
}
void SymbolTable::reportRemainingUndefines() {
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=246823&r1=246822&r2=246823&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Thu Sep 3 19:09:43 2015
@@ -54,6 +54,7 @@ public:
}
private:
+ template <class ELFT> void addELFFile(ELFFileBase *File);
void addELFFile(ELFFileBase *File);
template <class ELFT> void init();
More information about the llvm-commits
mailing list