diff options
Diffstat (limited to 'include/llvm/MC/MCSymbol.h')
-rw-r--r-- | include/llvm/MC/MCSymbol.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h index 53443b0..e4bdfda 100644 --- a/include/llvm/MC/MCSymbol.h +++ b/include/llvm/MC/MCSymbol.h @@ -15,6 +15,7 @@ #define LLVM_MC_MCSYMBOL_H #include "llvm/ADT/StringRef.h" +#include "llvm/MC/MCExpr.h" #include "llvm/Support/Compiler.h" namespace llvm { @@ -42,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; @@ -68,6 +70,12 @@ namespace llvm { MCSymbol(const MCSymbol&) = delete; void operator=(const MCSymbol&) = delete; + const MCSection *getSectionPtr() const { + if (Section || !Value) + return Section; + return Section = Value->FindAssociatedSection(); + } + public: /// getName - Get the symbol name. StringRef getName() const { return Name; } @@ -103,7 +111,7 @@ namespace llvm { /// /// Defined symbols are either absolute or in some section. bool isDefined() const { - return Section != nullptr; + return getSectionPtr() != nullptr; } /// isInSection - Check if this symbol is defined in some section (i.e., it @@ -119,27 +127,27 @@ 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 \p S. - void setSection(const MCSection &S) { Section = &S; } + void setSection(const MCSection &S) { + assert(!isVariable() && "Cannot set section of variable"); + Section = &S; + } /// setUndefined - Mark the symbol as undefined. void setUndefined() { Section = nullptr; } - /// setAbsolute - Mark the symbol as absolute. - void setAbsolute() { Section = AbsolutePseudoSection; } - /// @} /// @name Variable Symbols /// @{ |