MC: Allow targets to stop symbol name quoting
[oota-llvm.git] / include / llvm / MC / MCSymbol.h
index 7da4d7c15e3bbc8e3313985f7a6cbdb76058130c..464fff4fccbd590ae969451a1d9e592384239629 100644 (file)
@@ -15,6 +15,8 @@
 #define LLVM_MC_MCSYMBOL_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/Support/Compiler.h"
 
 namespace llvm {
   class MCExpr;
@@ -41,8 +43,9 @@ namespace llvm {
 
     /// Section - The section the symbol is defined in. This is null for
     /// undefined symbols, and the special AbsolutePseudoSection value for
-    /// absolute symbols.
-    const MCSection *Section;
+    /// absolute symbols. If this is a variable symbol, this caches the
+    /// variable value's section.
+    mutable const MCSection *Section;
 
     /// Value - If non-null, the value for a variable symbol.
     const MCExpr *Value;
@@ -52,17 +55,32 @@ namespace llvm {
     /// "Lfoo" or ".foo".
     unsigned IsTemporary : 1;
 
+    /// True if the name should be quoted if "unacceptable" characters are used
+    /// in the name.
+    unsigned NoQuoting : 1;
+
+    /// \brief True if this symbol can be redefined.
+    unsigned IsRedefinable : 1;
+
     /// IsUsed - True if this symbol has been used.
     mutable unsigned IsUsed : 1;
 
   private:  // MCContext creates and uniques these.
+    friend class MCExpr;
     friend class MCContext;
-    MCSymbol(StringRef name, bool isTemporary)
-      : Name(name), Section(0), Value(0),
-        IsTemporary(isTemporary), IsUsed(false) {}
+    MCSymbol(StringRef name, bool isTemporary, bool noQuoting)
+      : Name(name), Section(nullptr), Value(nullptr),
+        IsTemporary(isTemporary), NoQuoting(noQuoting),
+        IsRedefinable(false), IsUsed(false) {}
+
+    MCSymbol(const MCSymbol&) = delete;
+    void operator=(const MCSymbol&) = delete;
+    const MCSection *getSectionPtr() const {
+      if (Section || !Value)
+        return Section;
+      return Section = Value->FindAssociatedSection();
+    }
 
-    MCSymbol(const MCSymbol&);       // DO NOT IMPLEMENT
-    void operator=(const MCSymbol&); // DO NOT IMPLEMENT
   public:
     /// getName - Get the symbol name.
     StringRef getName() const { return Name; }
@@ -77,6 +95,19 @@ namespace llvm {
     bool isUsed() const { return IsUsed; }
     void setUsed(bool Value) const { IsUsed = Value; }
 
+    /// \brief Check if this symbol is redefinable.
+    bool isRedefinable() const { return IsRedefinable; }
+    /// \brief Mark this symbol as redefinable.
+    void setRedefinable(bool Value) { IsRedefinable = Value; }
+    /// \brief Prepare this symbol to be redefined.
+    void redefineIfPossible() {
+      if (IsRedefinable) {
+        Value = nullptr;
+        Section = nullptr;
+        IsRedefinable = false;
+      }
+    }
+
     /// @}
     /// @name Associated Sections
     /// @{
@@ -85,7 +116,7 @@ namespace llvm {
     ///
     /// Defined symbols are either absolute or in some section.
     bool isDefined() const {
-      return Section != 0;
+      return getSectionPtr() != nullptr;
     }
 
     /// isInSection - Check if this symbol is defined in some section (i.e., it
@@ -101,53 +132,48 @@ namespace llvm {
 
     /// isAbsolute - Check if this is an absolute symbol.
     bool isAbsolute() const {
-      return Section == AbsolutePseudoSection;
+      return getSectionPtr() == AbsolutePseudoSection;
     }
 
     /// getSection - Get the section associated with a defined, non-absolute
     /// symbol.
     const MCSection &getSection() const {
       assert(isInSection() && "Invalid accessor!");
-      return *Section;
+      return *getSectionPtr();
     }
 
-    /// setSection - Mark the symbol as defined in the section \arg S.
-    void setSection(const MCSection &S) { Section = &S; }
+    /// setSection - Mark the symbol as defined in the section \p S.
+    void setSection(const MCSection &S) {
+      assert(!isVariable() && "Cannot set section of variable");
+      Section = &S;
+    }
 
     /// setUndefined - Mark the symbol as undefined.
     void setUndefined() {
-      Section = 0;
+      Section = nullptr;
     }
 
-    /// setAbsolute - Mark the symbol as absolute.
-    void setAbsolute() { Section = AbsolutePseudoSection; }
-
     /// @}
     /// @name Variable Symbols
     /// @{
 
     /// isVariable - Check if this is a variable symbol.
     bool isVariable() const {
-      return Value != 0;
+      return Value != nullptr;
     }
 
-    /// getValue() - Get the value for variable symbols.
+    /// getVariableValue() - Get the value for variable symbols.
     const MCExpr *getVariableValue() const {
       assert(isVariable() && "Invalid accessor!");
       IsUsed = true;
       return Value;
     }
 
-    // AliasedSymbol() - If this is an alias (a = b), return the symbol
-    // we ultimately point to. For a non alias, this just returns the symbol
-    // itself.
-    const MCSymbol &AliasedSymbol() const;
-
     void setVariableValue(const MCExpr *Value);
 
     /// @}
 
-    /// print - Print the value to the stream \arg OS.
+    /// print - Print the value to the stream \p OS.
     void print(raw_ostream &OS) const;
 
     /// dump - Print the value to stderr.