forked from OSchip/llvm-project
[WebAssembly] Reduce code repetition. NFC.
Differential Revision: https://reviews.llvm.org/D43910 llvm-svn: 326379
This commit is contained in:
parent
1584f9eddd
commit
b961abc886
|
@ -125,31 +125,23 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef Name,
|
||||||
const WasmSignature *Type,
|
const WasmSignature *Type,
|
||||||
uint32_t Flags) {
|
uint32_t Flags) {
|
||||||
DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n");
|
DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n");
|
||||||
Symbol *S;
|
assert(!find(Name));
|
||||||
bool WasInserted;
|
return replaceSymbol<DefinedFunction>(insert(Name).first, Name, Flags, Type);
|
||||||
std::tie(S, WasInserted) = insert(Name);
|
|
||||||
assert(WasInserted);
|
|
||||||
return replaceSymbol<DefinedFunction>(S, Name, Flags, Type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name,
|
DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name,
|
||||||
uint32_t Flags) {
|
uint32_t Flags) {
|
||||||
DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n");
|
DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n");
|
||||||
Symbol *S;
|
assert(!find(Name));
|
||||||
bool WasInserted;
|
return replaceSymbol<DefinedData>(insert(Name).first, Name, Flags);
|
||||||
std::tie(S, WasInserted) = insert(Name);
|
|
||||||
assert(WasInserted);
|
|
||||||
return replaceSymbol<DefinedData>(S, Name, Flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags,
|
DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags,
|
||||||
InputGlobal *Global) {
|
InputGlobal *Global) {
|
||||||
DEBUG(dbgs() << "addSyntheticGlobal: " << Name << " -> " << Global << "\n");
|
DEBUG(dbgs() << "addSyntheticGlobal: " << Name << " -> " << Global << "\n");
|
||||||
Symbol *S;
|
assert(!find(Name));
|
||||||
bool WasInserted;
|
return replaceSymbol<DefinedGlobal>(insert(Name).first, Name, Flags, nullptr,
|
||||||
std::tie(S, WasInserted) = insert(Name);
|
Global);
|
||||||
assert(WasInserted);
|
|
||||||
return replaceSymbol<DefinedGlobal>(S, Name, Flags, nullptr, Global);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool shouldReplace(const Symbol *Existing, InputFile *NewFile,
|
static bool shouldReplace(const Symbol *Existing, InputFile *NewFile,
|
||||||
|
@ -251,7 +243,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags,
|
||||||
if (WasInserted)
|
if (WasInserted)
|
||||||
replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
|
replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
|
||||||
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
||||||
cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
|
Lazy->fetch();
|
||||||
else if (S->isDefined())
|
else if (S->isDefined())
|
||||||
checkFunctionType(S, File, Sig);
|
checkFunctionType(S, File, Sig);
|
||||||
return S;
|
return S;
|
||||||
|
@ -268,7 +260,7 @@ Symbol *SymbolTable::addUndefinedData(StringRef Name, uint32_t Flags,
|
||||||
if (WasInserted)
|
if (WasInserted)
|
||||||
replaceSymbol<UndefinedData>(S, Name, Flags, File);
|
replaceSymbol<UndefinedData>(S, Name, Flags, File);
|
||||||
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
||||||
cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
|
Lazy->fetch();
|
||||||
else if (S->isDefined())
|
else if (S->isDefined())
|
||||||
checkDataType(S, File);
|
checkDataType(S, File);
|
||||||
return S;
|
return S;
|
||||||
|
@ -286,7 +278,7 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, uint32_t Flags,
|
||||||
if (WasInserted)
|
if (WasInserted)
|
||||||
replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
|
replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
|
||||||
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
else if (auto *Lazy = dyn_cast<LazySymbol>(S))
|
||||||
cast<ArchiveFile>(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol());
|
Lazy->fetch();
|
||||||
else if (S->isDefined())
|
else if (S->isDefined())
|
||||||
checkGlobalType(S, File, Type);
|
checkGlobalType(S, File, Type);
|
||||||
return S;
|
return S;
|
||||||
|
|
|
@ -178,6 +178,8 @@ DefinedGlobal::DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
|
||||||
Global ? &Global->getType() : nullptr),
|
Global ? &Global->getType() : nullptr),
|
||||||
Global(Global) {}
|
Global(Global) {}
|
||||||
|
|
||||||
|
void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
|
||||||
|
|
||||||
std::string lld::toString(const wasm::Symbol &Sym) {
|
std::string lld::toString(const wasm::Symbol &Sym) {
|
||||||
if (Config->Demangle)
|
if (Config->Demangle)
|
||||||
if (Optional<std::string> S = demangleItanium(Sym.getName()))
|
if (Optional<std::string> S = demangleItanium(Sym.getName()))
|
||||||
|
|
|
@ -257,10 +257,9 @@ public:
|
||||||
: Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {}
|
: Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {}
|
||||||
|
|
||||||
static bool classof(const Symbol *S) { return S->kind() == LazyKind; }
|
static bool classof(const Symbol *S) { return S->kind() == LazyKind; }
|
||||||
|
void fetch();
|
||||||
|
|
||||||
const Archive::Symbol &getArchiveSymbol() { return ArchiveSymbol; }
|
private:
|
||||||
|
|
||||||
protected:
|
|
||||||
Archive::Symbol ArchiveSymbol;
|
Archive::Symbol ArchiveSymbol;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue