From 62f764a6c96d371eb36b59d4c59fb7918d4b89db Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Mon, 8 Jun 2015 17:17:09 +0000 Subject: [PATCH] Change MCSymbol IsELF to an enum to support future MCSymbolCOFF and MCSymbolMachO. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed by Rafael Espíndola. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239311 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCSymbol.h | 22 ++++++++++++++++++---- include/llvm/MC/MCSymbolELF.h | 2 +- lib/MC/MCContext.cpp | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h index 7f74f378d46..5710051840e 100644 --- a/include/llvm/MC/MCSymbol.h +++ b/include/llvm/MC/MCSymbol.h @@ -35,6 +35,16 @@ class raw_ostream; /// 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? @@ -83,7 +93,7 @@ class MCSymbol { mutable unsigned HasFragment : 1; - unsigned IsELF : 1; + SymbolKind Kind : 2; /// Index field, for use by the object file implementation. mutable uint32_t Index = 0; @@ -108,11 +118,11 @@ class MCSymbol { protected: // MCContext creates and uniques these. friend class MCExpr; friend class MCContext; - MCSymbol(bool IsELF, const StringMapEntry *Name, bool isTemporary) + MCSymbol(SymbolKind Kind, const StringMapEntry *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; } @@ -197,7 +207,11 @@ public: 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 diff --git a/include/llvm/MC/MCSymbolELF.h b/include/llvm/MC/MCSymbolELF.h index c943054a4fd..0cc11156b5c 100644 --- a/include/llvm/MC/MCSymbolELF.h +++ b/include/llvm/MC/MCSymbolELF.h @@ -19,7 +19,7 @@ class MCSymbolELF : public MCSymbol { public: MCSymbolELF(const StringMapEntry *Name, bool isTemporary) - : MCSymbol(true, Name, isTemporary) {} + : MCSymbol(SymbolKindELF, Name, isTemporary) {} void setSize(const MCExpr *SS) { SymbolSize = SS; } const MCExpr *getSize() const { return SymbolSize; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 79f9bdae463..b44cbc0f85b 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -162,7 +162,7 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry *Name, 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, -- 2.34.1