Index: wasm/Symbols.h =================================================================== --- wasm/Symbols.h +++ wasm/Symbols.h @@ -22,6 +22,7 @@ class InputFile; class InputChunk; +class InputSegment; class InputFunction; #define INVALID_INDEX UINT32_MAX @@ -58,7 +59,7 @@ // Returns the file from which this symbol was created. InputFile *getFile() const { return File; } - InputChunk *getChunk() const { return Chunk; } + InputChunk *getChunk() const; void setHidden(bool IsHidden); @@ -72,14 +73,13 @@ void setOutputIndex(uint32_t Index); protected: - Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, InputChunk *C) - : Name(Name), SymbolKind(K), Flags(Flags), File(F), Chunk(C) {} + Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) + : Name(Name), SymbolKind(K), Flags(Flags), File(F) {} StringRef Name; Kind SymbolKind; uint32_t Flags; InputFile *File; - InputChunk *Chunk; uint32_t OutputIndex = INVALID_INDEX; }; @@ -102,11 +102,8 @@ protected: FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - InputFunction *Function); - - FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - const WasmSignature* Type) - : Symbol(Name, K, Flags, F, nullptr), FunctionType(Type) {} + const WasmSignature *Type) + : Symbol(Name, K, Flags, F), FunctionType(Type) {} uint32_t TableIndex = INVALID_INDEX; @@ -116,8 +113,7 @@ class DefinedFunction : public FunctionSymbol { public: DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, - InputFunction *Function) - : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, Function) {} + InputFunction *Function); DefinedFunction(StringRef Name, uint32_t Flags, const WasmSignature *Type) : FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, Type) {} @@ -125,6 +121,8 @@ static bool classof(const Symbol *S) { return S->kind() == DefinedFunctionKind; } + + InputFunction *Function; }; class UndefinedFunction : public FunctionSymbol { @@ -145,16 +143,15 @@ } protected: - GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - InputChunk *C) - : Symbol(Name, K, Flags, F, C) {} + GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) + : Symbol(Name, K, Flags, F) {} }; class DefinedGlobal : public GlobalSymbol { public: DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *F = nullptr, - InputChunk *C = nullptr, uint32_t Address = 0) - : GlobalSymbol(Name, DefinedGlobalKind, Flags, F, C), + InputSegment *Segment = nullptr, uint32_t Address = 0) + : GlobalSymbol(Name, DefinedGlobalKind, Flags, F), Segment(Segment), VirtualAddress(Address) {} static bool classof(const Symbol *S) { @@ -162,9 +159,10 @@ } uint32_t getVirtualAddress() const; - void setVirtualAddress(uint32_t VA); + InputSegment *Segment; + protected: uint32_t VirtualAddress; }; @@ -172,7 +170,7 @@ class UndefinedGlobal : public GlobalSymbol { public: UndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File = nullptr) - : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, nullptr) {} + : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File) {} static bool classof(const Symbol *S) { return S->kind() == UndefinedGlobalKind; } @@ -181,7 +179,7 @@ class LazySymbol : public Symbol { public: LazySymbol(StringRef Name, InputFile *File, const Archive::Symbol &Sym) - : Symbol(Name, LazyKind, 0, File, nullptr), ArchiveSymbol(Sym) {} + : Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {} static bool classof(const Symbol *S) { return S->kind() == LazyKind; } Index: wasm/Symbols.cpp =================================================================== --- wasm/Symbols.cpp +++ wasm/Symbols.cpp @@ -29,21 +29,30 @@ DefinedGlobal *WasmSym::StackPointer; bool Symbol::hasOutputIndex() const { - if (auto *F = dyn_cast_or_null(Chunk)) - return F->hasOutputIndex(); + if (auto *F = dyn_cast(this)) + if (F->Function) + return F->Function->hasOutputIndex(); return OutputIndex != INVALID_INDEX; } uint32_t Symbol::getOutputIndex() const { - if (auto *F = dyn_cast_or_null(Chunk)) - return F->getOutputIndex(); + if (auto *F = dyn_cast(this)) + if (F->Function) + return F->Function->getOutputIndex(); assert(OutputIndex != INVALID_INDEX); return OutputIndex; } +InputChunk *Symbol::getChunk() const { + if (auto *F = dyn_cast(this)) + return F->Function; + if (auto *G = dyn_cast(this)) + return G->Segment; + return nullptr; +} + void Symbol::setOutputIndex(uint32_t Index) { DEBUG(dbgs() << "setOutputIndex " << Name << " -> " << Index << "\n"); - assert(!dyn_cast_or_null(Chunk)); assert(OutputIndex == INVALID_INDEX); OutputIndex = Index; } @@ -69,20 +78,16 @@ Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT; } -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(Chunk)) - return F->getTableIndex(); + if (auto *F = dyn_cast(this)) + return F->Function->getTableIndex(); assert(TableIndex != INVALID_INDEX); return TableIndex; } bool FunctionSymbol::hasTableIndex() const { - if (auto *F = dyn_cast_or_null(Chunk)) - return F->hasTableIndex(); + if (auto *F = dyn_cast(this)) + return F->Function->hasTableIndex(); return TableIndex != INVALID_INDEX; } @@ -90,8 +95,8 @@ // For imports, we set the table index here on the Symbol; for defined // functions we set the index on the InputFunction so that we don't export // the same thing twice (keeps the table size down). - if (auto *F = dyn_cast_or_null(Chunk)) { - F->setTableIndex(Index); + if (auto *F = dyn_cast(this)) { + F->Function->setTableIndex(Index); return; } DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n"); @@ -99,10 +104,15 @@ TableIndex = Index; } +DefinedFunction::DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, + InputFunction *Function) + : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, + Function ? &Function->Signature : nullptr), + Function(Function) {} + uint32_t DefinedGlobal::getVirtualAddress() const { DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n"); - return Chunk ? dyn_cast(Chunk)->translateVA(VirtualAddress) - : VirtualAddress; + return Segment ? Segment->translateVA(VirtualAddress) : VirtualAddress; } void DefinedGlobal::setVirtualAddress(uint32_t Value) {