forked from OSchip/llvm-project
[WebAssembly] Simplify FunctionSymbol::get/set/hasFunctionType. NFC.
Differential Revision: https://reviews.llvm.org/D43416 llvm-svn: 325415
This commit is contained in:
parent
6d83fb4c07
commit
3f8db98807
|
@ -303,17 +303,17 @@ Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind,
|
|||
}
|
||||
|
||||
Symbol *ObjFile::createDefinedFunction(const WasmSymbol &Sym,
|
||||
InputChunk *Chunk) {
|
||||
InputFunction *Function) {
|
||||
if (Sym.isBindingLocal())
|
||||
return make<DefinedFunction>(Sym.Name, Sym.Flags, this, Chunk);
|
||||
return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Chunk);
|
||||
return make<DefinedFunction>(Sym.Name, Sym.Flags, this, Function);
|
||||
return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Function);
|
||||
}
|
||||
|
||||
Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk,
|
||||
uint32_t Address) {
|
||||
Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym,
|
||||
InputSegment *Segment, uint32_t Address) {
|
||||
if (Sym.isBindingLocal())
|
||||
return make<DefinedGlobal>(Sym.Name, Sym.Flags, this, Chunk, Address);
|
||||
return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Chunk, Address);
|
||||
return make<DefinedGlobal>(Sym.Name, Sym.Flags, this, Segment, Address);
|
||||
return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Segment, Address);
|
||||
}
|
||||
|
||||
void ArchiveFile::parse() {
|
||||
|
|
|
@ -121,9 +121,9 @@ private:
|
|||
uint32_t relocateGlobalIndex(uint32_t Original) const;
|
||||
uint32_t relocateTableIndex(uint32_t Original) const;
|
||||
|
||||
Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk,
|
||||
Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputSegment *Segment,
|
||||
uint32_t Address);
|
||||
Symbol *createDefinedFunction(const WasmSymbol &Sym, InputChunk *Chunk);
|
||||
Symbol *createDefinedFunction(const WasmSymbol &Sym, InputFunction *Function);
|
||||
Symbol *createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind,
|
||||
const WasmSignature *Signature = nullptr);
|
||||
void initializeSymbols();
|
||||
|
|
|
@ -99,20 +99,21 @@ static void checkSymbolTypes(const Symbol &Existing, const InputFile &F,
|
|||
if (!ExistingFunc || !Config->CheckSignatures)
|
||||
return;
|
||||
|
||||
const WasmSignature *OldSig = ExistingFunc->getFunctionType();
|
||||
|
||||
// Skip the signature check if the existing function has no signature (e.g.
|
||||
// if it is an undefined symbol generated by --undefined command line flag).
|
||||
if (!ExistingFunc->hasFunctionType())
|
||||
if (OldSig == nullptr)
|
||||
return;
|
||||
|
||||
DEBUG(dbgs() << "checkSymbolTypes: " << ExistingFunc->getName() << "\n");
|
||||
assert(NewSig);
|
||||
|
||||
const WasmSignature &OldSig = ExistingFunc->getFunctionType();
|
||||
if (*NewSig == OldSig)
|
||||
if (*NewSig == *OldSig)
|
||||
return;
|
||||
|
||||
error("function signature mismatch: " + ExistingFunc->getName() +
|
||||
"\n>>> defined as " + toString(OldSig) + " in " +
|
||||
"\n>>> defined as " + toString(*OldSig) + " in " +
|
||||
toString(ExistingFunc->getFile()) + "\n>>> defined as " +
|
||||
toString(*NewSig) + " in " + F.getName());
|
||||
}
|
||||
|
@ -188,9 +189,11 @@ Symbol *SymbolTable::addDefined(bool IsFunction, StringRef Name, uint32_t Flags,
|
|||
if (CheckTypes)
|
||||
checkSymbolTypes(*S, *F, IsFunction, Chunk);
|
||||
if (IsFunction)
|
||||
replaceSymbol<DefinedFunction>(S, Name, Flags, F, Chunk);
|
||||
replaceSymbol<DefinedFunction>(S, Name, Flags, F,
|
||||
cast<InputFunction>(Chunk));
|
||||
else
|
||||
replaceSymbol<DefinedGlobal>(S, Name, Flags, F, Chunk, Address);
|
||||
replaceSymbol<DefinedGlobal>(S, Name, Flags, F, cast<InputSegment>(Chunk),
|
||||
Address);
|
||||
}
|
||||
return S;
|
||||
}
|
||||
|
|
|
@ -69,19 +69,9 @@ void Symbol::setHidden(bool IsHidden) {
|
|||
Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT;
|
||||
}
|
||||
|
||||
const WasmSignature &FunctionSymbol::getFunctionType() const {
|
||||
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
|
||||
return F->Signature;
|
||||
|
||||
assert(FunctionType != nullptr);
|
||||
return *FunctionType;
|
||||
}
|
||||
|
||||
void FunctionSymbol::setFunctionType(const WasmSignature *Type) {
|
||||
assert(FunctionType == nullptr);
|
||||
assert(!Chunk);
|
||||
FunctionType = Type;
|
||||
}
|
||||
FunctionSymbol::FunctionSymbol(StringRef Name, Kind K, uint32_t Flags,
|
||||
InputFile *F, InputFunction *Function)
|
||||
: Symbol(Name, K, Flags, F, Function), FunctionType(&Function->Signature) {}
|
||||
|
||||
uint32_t FunctionSymbol::getTableIndex() const {
|
||||
if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace wasm {
|
|||
|
||||
class InputFile;
|
||||
class InputChunk;
|
||||
class InputFunction;
|
||||
|
||||
#define INVALID_INDEX UINT32_MAX
|
||||
|
||||
|
@ -94,8 +95,7 @@ public:
|
|||
S->kind() == UndefinedFunctionKind;
|
||||
}
|
||||
|
||||
bool hasFunctionType() const { return Chunk || FunctionType; }
|
||||
const WasmSignature &getFunctionType() const;
|
||||
const WasmSignature *getFunctionType() const { return FunctionType; }
|
||||
|
||||
uint32_t getTableIndex() const;
|
||||
|
||||
|
@ -106,28 +106,26 @@ public:
|
|||
void setTableIndex(uint32_t Index);
|
||||
|
||||
protected:
|
||||
void setFunctionType(const WasmSignature *Type);
|
||||
FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
|
||||
InputFunction *Function);
|
||||
|
||||
FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F,
|
||||
InputChunk *C)
|
||||
: Symbol(Name, K, Flags, F, C) {}
|
||||
const WasmSignature* Type)
|
||||
: Symbol(Name, K, Flags, F, nullptr), FunctionType(Type) {}
|
||||
|
||||
uint32_t TableIndex = INVALID_INDEX;
|
||||
|
||||
// Explict function type, needed for undefined or synthetic functions only.
|
||||
const WasmSignature *FunctionType = nullptr;
|
||||
const WasmSignature *FunctionType;
|
||||
};
|
||||
|
||||
class DefinedFunction : public FunctionSymbol {
|
||||
public:
|
||||
DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F = nullptr,
|
||||
InputChunk *C = nullptr)
|
||||
: FunctionSymbol(Name, DefinedFunctionKind, Flags, F, C) {}
|
||||
DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F,
|
||||
InputFunction *Function)
|
||||
: FunctionSymbol(Name, DefinedFunctionKind, Flags, F, Function) {}
|
||||
|
||||
DefinedFunction(StringRef Name, uint32_t Flags, const WasmSignature *Type)
|
||||
: FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, nullptr) {
|
||||
setFunctionType(Type);
|
||||
}
|
||||
: FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, Type) {}
|
||||
|
||||
static bool classof(const Symbol *S) {
|
||||
return S->kind() == DefinedFunctionKind;
|
||||
|
@ -138,9 +136,7 @@ class UndefinedFunction : public FunctionSymbol {
|
|||
public:
|
||||
UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
|
||||
const WasmSignature *Type = nullptr)
|
||||
: FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, nullptr) {
|
||||
setFunctionType(Type);
|
||||
}
|
||||
: FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {}
|
||||
|
||||
static bool classof(const Symbol *S) {
|
||||
return S->kind() == UndefinedFunctionKind;
|
||||
|
|
|
@ -169,7 +169,7 @@ void Writer::createImportSection() {
|
|||
Import.Module = "env";
|
||||
Import.Field = Sym->getName();
|
||||
Import.Kind = WASM_EXTERNAL_FUNCTION;
|
||||
Import.SigIndex = lookupType(Sym->getFunctionType());
|
||||
Import.SigIndex = lookupType(*Sym->getFunctionType());
|
||||
writeImport(OS, Import);
|
||||
}
|
||||
|
||||
|
@ -713,7 +713,7 @@ void Writer::calculateTypes() {
|
|||
}
|
||||
|
||||
for (const FunctionSymbol *Sym : ImportedFunctions)
|
||||
registerType(Sym->getFunctionType());
|
||||
registerType(*Sym->getFunctionType());
|
||||
|
||||
for (const InputFunction *F : DefinedFunctions)
|
||||
registerType(F->Signature);
|
||||
|
|
Loading…
Reference in New Issue