DefinedGlobal *WasmSym::StackPointer;
bool Symbol::hasOutputIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->hasOutputIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ if (F->Function)
+ return F->Function->hasOutputIndex();
return OutputIndex != INVALID_INDEX;
}
uint32_t Symbol::getOutputIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->getOutputIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ if (F->Function)
+ return F->Function->getOutputIndex();
assert(OutputIndex != INVALID_INDEX);
return OutputIndex;
}
+InputChunk *Symbol::getChunk() const {
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function;
+ if (auto *G = dyn_cast<DefinedGlobal>(this))
+ return G->Segment;
+ return nullptr;
+}
+
void Symbol::setOutputIndex(uint32_t Index) {
DEBUG(dbgs() << "setOutputIndex " << Name << " -> " << Index << "\n");
- assert(!dyn_cast_or_null<InputFunction>(Chunk));
assert(OutputIndex == INVALID_INDEX);
OutputIndex = Index;
}
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<InputFunction>(Chunk))
- return F->getTableIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function->getTableIndex();
assert(TableIndex != INVALID_INDEX);
return TableIndex;
}
bool FunctionSymbol::hasTableIndex() const {
- if (auto *F = dyn_cast_or_null<InputFunction>(Chunk))
- return F->hasTableIndex();
+ if (auto *F = dyn_cast<DefinedFunction>(this))
+ return F->Function->hasTableIndex();
return TableIndex != INVALID_INDEX;
}
// 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<InputFunction>(Chunk)) {
- F->setTableIndex(Index);
+ if (auto *F = dyn_cast<DefinedFunction>(this)) {
+ F->Function->setTableIndex(Index);
return;
}
DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
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<InputSegment>(Chunk)->translateVA(VirtualAddress)
- : VirtualAddress;
+ return Segment ? Segment->translateVA(VirtualAddress) : VirtualAddress;
}
void DefinedGlobal::setVirtualAddress(uint32_t Value) {
class InputFile;
class InputChunk;
+class InputSegment;
class InputFunction;
#define INVALID_INDEX UINT32_MAX
// 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);
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;
};
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;
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) {}
static bool classof(const Symbol *S) {
return S->kind() == DefinedFunctionKind;
}
+
+ InputFunction *Function;
};
class UndefinedFunction : public FunctionSymbol {
}
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) {
}
uint32_t getVirtualAddress() const;
-
void setVirtualAddress(uint32_t VA);
+ InputSegment *Segment;
+
protected:
uint32_t VirtualAddress;
};
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;
}
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; }