From b961abc8863292a00e9431b203346f815bfd9724 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 28 Feb 2018 22:51:51 +0000 Subject: [PATCH] [WebAssembly] Reduce code repetition. NFC. Differential Revision: https://reviews.llvm.org/D43910 llvm-svn: 326379 --- lld/wasm/SymbolTable.cpp | 28 ++++++++++------------------ lld/wasm/Symbols.cpp | 2 ++ lld/wasm/Symbols.h | 5 ++--- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index b9f4e6e5e3a2..bf7d33c359e6 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -125,31 +125,23 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef Name, 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(S, Name, Flags, Type); + assert(!find(Name)); + return replaceSymbol(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(S, Name, Flags); + assert(!find(Name)); + return replaceSymbol(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(S, Name, Flags, nullptr, Global); + assert(!find(Name)); + return replaceSymbol(insert(Name).first, Name, Flags, nullptr, + Global); } static bool shouldReplace(const Symbol *Existing, InputFile *NewFile, @@ -251,7 +243,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags, if (WasInserted) replaceSymbol(S, Name, Flags, File, Sig); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkFunctionType(S, File, Sig); return S; @@ -268,7 +260,7 @@ Symbol *SymbolTable::addUndefinedData(StringRef Name, uint32_t Flags, if (WasInserted) replaceSymbol(S, Name, Flags, File); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkDataType(S, File); return S; @@ -286,7 +278,7 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, uint32_t Flags, if (WasInserted) replaceSymbol(S, Name, Flags, File, Type); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkGlobalType(S, File, Type); return S; diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp index f968c9ddcf81..742c887412dd 100644 --- a/lld/wasm/Symbols.cpp +++ b/lld/wasm/Symbols.cpp @@ -178,6 +178,8 @@ DefinedGlobal::DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File, Global ? &Global->getType() : nullptr), Global(Global) {} +void LazySymbol::fetch() { cast(File)->addMember(&ArchiveSymbol); } + std::string lld::toString(const wasm::Symbol &Sym) { if (Config->Demangle) if (Optional S = demangleItanium(Sym.getName())) diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index db0598fca534..90e62e5af114 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -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; };