1 //===- MCSymbol.h - Machine Code Symbols ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the MCSymbol class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSYMBOL_H
15 #define LLVM_MC_MCSYMBOL_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h"
26 /// MCSymbol - Instances of this class represent a symbol name in the MC file,
27 /// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
28 /// should only be constructed with valid names for the object file.
30 /// If the symbol is defined/emitted into the current translation unit, the
31 /// Section member is set to indicate what section it lives in. Otherwise, if
32 /// it is a reference to an external entity, it has a null section.
34 // Special sentinal value for the absolute pseudo section.
36 // FIXME: Use a PointerInt wrapper for this?
37 static const MCSection *AbsolutePseudoSection;
39 /// Name - The name of the symbol. The referred-to string data is actually
40 /// held by the StringMap that lives in MCContext.
43 /// Section - The section the symbol is defined in. This is null for
44 /// undefined symbols, and the special AbsolutePseudoSection value for
46 const MCSection *Section;
48 /// Value - If non-null, the value for a variable symbol.
51 /// IsTemporary - True if this is an assembler temporary label, which
52 /// typically does not survive in the .o file's symbol table. Usually
54 unsigned IsTemporary : 1;
56 /// IsUsed - True if this symbol has been used.
57 mutable unsigned IsUsed : 1;
59 private: // MCContext creates and uniques these.
61 friend class MCContext;
62 MCSymbol(StringRef name, bool isTemporary)
63 : Name(name), Section(0), Value(0),
64 IsTemporary(isTemporary), IsUsed(false) {}
66 MCSymbol(const MCSymbol&) LLVM_DELETED_FUNCTION;
67 void operator=(const MCSymbol&) LLVM_DELETED_FUNCTION;
69 /// getName - Get the symbol name.
70 StringRef getName() const { return Name; }
75 /// isTemporary - Check if this is an assembler temporary symbol.
76 bool isTemporary() const { return IsTemporary; }
78 /// isUsed - Check if this is used.
79 bool isUsed() const { return IsUsed; }
80 void setUsed(bool Value) const { IsUsed = Value; }
83 /// @name Associated Sections
86 /// isDefined - Check if this symbol is defined (i.e., it has an address).
88 /// Defined symbols are either absolute or in some section.
89 bool isDefined() const {
93 /// isInSection - Check if this symbol is defined in some section (i.e., it
94 /// is defined but not absolute).
95 bool isInSection() const {
96 return isDefined() && !isAbsolute();
99 /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
100 bool isUndefined() const {
104 /// isAbsolute - Check if this is an absolute symbol.
105 bool isAbsolute() const {
106 return Section == AbsolutePseudoSection;
109 /// getSection - Get the section associated with a defined, non-absolute
111 const MCSection &getSection() const {
112 assert(isInSection() && "Invalid accessor!");
116 /// setSection - Mark the symbol as defined in the section \p S.
117 void setSection(const MCSection &S) { Section = &S; }
119 /// setUndefined - Mark the symbol as undefined.
120 void setUndefined() {
124 /// setAbsolute - Mark the symbol as absolute.
125 void setAbsolute() { Section = AbsolutePseudoSection; }
128 /// @name Variable Symbols
131 /// isVariable - Check if this is a variable symbol.
132 bool isVariable() const {
136 /// getVariableValue() - Get the value for variable symbols.
137 const MCExpr *getVariableValue() const {
138 assert(isVariable() && "Invalid accessor!");
143 // AliasedSymbol() - If this is an alias (a = b), return the symbol
144 // we ultimately point to. For a non alias, this just returns the symbol
146 const MCSymbol &AliasedSymbol() const;
148 void setVariableValue(const MCExpr *Value);
152 /// print - Print the value to the stream \p OS.
153 void print(raw_ostream &OS) const;
155 /// dump - Print the value to stderr.
159 inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
163 } // end namespace llvm