[llvm] r239311 - Change MCSymbol IsELF to an enum to support future MCSymbolCOFF and MCSymbolMachO.

Pete Cooper peter_cooper at apple.com
Mon Jun 8 10:17:09 PDT 2015


Author: pete
Date: Mon Jun  8 12:17:09 2015
New Revision: 239311

URL: http://llvm.org/viewvc/llvm-project?rev=239311&view=rev
Log:
Change MCSymbol IsELF to an enum to support future MCSymbolCOFF and MCSymbolMachO.

Reviewed by Rafael EspĂ­ndola.

Modified:
    llvm/trunk/include/llvm/MC/MCSymbol.h
    llvm/trunk/include/llvm/MC/MCSymbolELF.h
    llvm/trunk/lib/MC/MCContext.cpp

Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=239311&r1=239310&r2=239311&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbol.h Mon Jun  8 12:17:09 2015
@@ -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<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;
   }
 
@@ -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

Modified: llvm/trunk/include/llvm/MC/MCSymbolELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbolELF.h?rev=239311&r1=239310&r2=239311&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolELF.h Mon Jun  8 12:17:09 2015
@@ -19,7 +19,7 @@ class MCSymbolELF : public MCSymbol {
 
 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; }

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=239311&r1=239310&r2=239311&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Mon Jun  8 12:17:09 2015
@@ -162,7 +162,7 @@ MCSymbol *MCContext::createSymbolImpl(co
   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,






More information about the llvm-commits mailing list