[lld] r326379 - [WebAssembly] Reduce code repetition. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 14:51:51 PST 2018
Author: ruiu
Date: Wed Feb 28 14:51:51 2018
New Revision: 326379
URL: http://llvm.org/viewvc/llvm-project?rev=326379&view=rev
Log:
[WebAssembly] Reduce code repetition. NFC.
Differential Revision: https://reviews.llvm.org/D43910
Modified:
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/Symbols.cpp
lld/trunk/wasm/Symbols.h
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=326379&r1=326378&r2=326379&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Wed Feb 28 14:51:51 2018
@@ -125,31 +125,23 @@ DefinedFunction *SymbolTable::addSynthet
const WasmSignature *Type,
uint32_t Flags) {
DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n");
- Symbol *S;
- bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
- assert(WasInserted);
- return replaceSymbol<DefinedFunction>(S, Name, Flags, Type);
+ assert(!find(Name));
+ return replaceSymbol<DefinedFunction>(insert(Name).first, Name, Flags, Type);
}
DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name,
uint32_t Flags) {
DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n");
- Symbol *S;
- bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
- assert(WasInserted);
- return replaceSymbol<DefinedData>(S, Name, Flags);
+ assert(!find(Name));
+ return replaceSymbol<DefinedData>(insert(Name).first, Name, Flags);
}
DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags,
InputGlobal *Global) {
DEBUG(dbgs() << "addSyntheticGlobal: " << Name << " -> " << Global << "\n");
- Symbol *S;
- bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
- assert(WasInserted);
- return replaceSymbol<DefinedGlobal>(S, Name, Flags, nullptr, Global);
+ assert(!find(Name));
+ return replaceSymbol<DefinedGlobal>(insert(Name).first, Name, Flags, nullptr,
+ Global);
}
static bool shouldReplace(const Symbol *Existing, InputFile *NewFile,
@@ -251,7 +243,7 @@ Symbol *SymbolTable::addUndefinedFunctio
if (WasInserted)
replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
- cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
+ Lazy->fetch();
else if (S->isDefined())
checkFunctionType(S, File, Sig);
return S;
@@ -268,7 +260,7 @@ Symbol *SymbolTable::addUndefinedData(St
if (WasInserted)
replaceSymbol<UndefinedData>(S, Name, Flags, File);
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
- cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
+ Lazy->fetch();
else if (S->isDefined())
checkDataType(S, File);
return S;
@@ -286,7 +278,7 @@ Symbol *SymbolTable::addUndefinedGlobal(
if (WasInserted)
replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
- cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
+ Lazy->fetch();
else if (S->isDefined())
checkGlobalType(S, File, Type);
return S;
Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=326379&r1=326378&r2=326379&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Wed Feb 28 14:51:51 2018
@@ -178,6 +178,8 @@ DefinedGlobal::DefinedGlobal(StringRef N
Global ? &Global->getType() : nullptr),
Global(Global) {}
+void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
+
std::string lld::toString(const wasm::Symbol &Sym) {
if (Config->Demangle)
if (Optional<std::string> S = demangleItanium(Sym.getName()))
Modified: lld/trunk/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.h?rev=326379&r1=326378&r2=326379&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.h (original)
+++ lld/trunk/wasm/Symbols.h Wed Feb 28 14:51:51 2018
@@ -257,10 +257,9 @@ public:
: Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {}
static bool classof(const Symbol *S) { return S->kind() == LazyKind; }
+ void fetch();
- const Archive::Symbol &getArchiveSymbol() { return ArchiveSymbol; }
-
-protected:
+private:
Archive::Symbol ArchiveSymbol;
};
More information about the llvm-commits
mailing list