[PATCH] D43910: [WebAssembly] Reduce code repetition. NFC.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 14:54:52 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD326379: [WebAssembly] Reduce code repetition. NFC. (authored by ruiu, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D43910?vs=136396&id=136404#toc
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D43910
Files:
wasm/SymbolTable.cpp
wasm/Symbols.cpp
wasm/Symbols.h
Index: wasm/SymbolTable.cpp
===================================================================
--- wasm/SymbolTable.cpp
+++ wasm/SymbolTable.cpp
@@ -125,31 +125,23 @@
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 @@
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 @@
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 @@
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;
Index: wasm/Symbols.h
===================================================================
--- wasm/Symbols.h
+++ wasm/Symbols.h
@@ -257,10 +257,9 @@
: 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;
};
Index: wasm/Symbols.cpp
===================================================================
--- wasm/Symbols.cpp
+++ wasm/Symbols.cpp
@@ -178,6 +178,8 @@
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()))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43910.136404.patch
Type: text/x-patch
Size: 3643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180228/7aee8061/attachment.bin>
More information about the llvm-commits
mailing list