#define LLVM_MC_MCSYMBOL_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/Support/Compiler.h"
namespace llvm {
class MCExpr;
/// 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;
/// "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; }
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
/// @{
///
/// 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
/// 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.