/// Section member is set to indicate what section it lives in. Otherwise, if
/// it is a reference to an external entity, it has a null section.
class MCSymbol {
+protected:
+ /// The kind of the symbol. If it is any value other than unset then this
+ /// class is actually one of the appropriate subclasses of MCSymbol.
+ enum SymbolKind {
+ SymbolKindUnset,
+ SymbolKindCOFF,
+ SymbolKindELF,
+ SymbolKindMachO,
+ };
+
// Special sentinal value for the absolute pseudo section.
//
// FIXME: Use a PointerInt wrapper for this?
mutable unsigned HasFragment : 1;
- unsigned IsELF : 1;
+ SymbolKind Kind : 2;
/// Index field, for use by the object file implementation.
mutable uint32_t Index = 0;
protected: // MCContext creates and uniques these.
friend class MCExpr;
friend class MCContext;
- MCSymbol(bool IsELF, const StringMapEntry<bool> *Name, bool isTemporary)
+ MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
: Name(Name), Section(nullptr), Value(nullptr), IsTemporary(isTemporary),
IsRedefinable(false), IsUsed(false), IsRegistered(false),
IsExternal(false), IsPrivateExtern(false), HasFragment(false),
- IsELF(IsELF) {
+ Kind(Kind) {
Offset = 0;
}
Section = nullptr;
}
- bool isELF() const { return IsELF; }
+ bool isELF() const { return Kind == SymbolKindELF; }
+
+ bool isCOFF() const { return Kind == SymbolKindCOFF; }
+
+ bool isMachO() const { return Kind == SymbolKindMachO; }
/// @}
/// \name Variable Symbols
public:
MCSymbolELF(const StringMapEntry<bool> *Name, bool isTemporary)
- : MCSymbol(true, Name, isTemporary) {}
+ : MCSymbol(SymbolKindELF, Name, isTemporary) {}
void setSize(const MCExpr *SS) { SymbolSize = SS; }
const MCExpr *getSize() const { return SymbolSize; }
bool IsELF = MOFI && MOFI->getObjectFileType() == MCObjectFileInfo::IsELF;
if (IsELF)
return new (*this) MCSymbolELF(Name, IsTemporary);
- return new (*this) MCSymbol(false, Name, IsTemporary);
+ return new (*this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
}
MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,