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"
25 /// MCSymbol - Instances of this class represent a symbol name in the MC file,
26 /// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
27 /// should only be constructed with valid names for the object file.
29 /// If the symbol is defined/emitted into the current translation unit, the
30 /// Section member is set to indicate what section it lives in. Otherwise, if
31 /// it is a reference to an external entity, it has a null section.
33 // Special sentinal value for the absolute pseudo section.
35 // FIXME: Use a PointerInt wrapper for this?
36 static const MCSection *AbsolutePseudoSection;
38 /// Name - The name of the symbol. The referred-to string data is actually
39 /// held by the StringMap that lives in MCContext.
42 /// Section - The section the symbol is defined in. This is null for
43 /// undefined symbols, and the special AbsolutePseudoSection value for
45 const MCSection *Section;
47 /// Value - If non-null, the value for a variable symbol.
50 /// IsTemporary - True if this is an assembler temporary label, which
51 /// typically does not survive in the .o file's symbol table. Usually
53 unsigned IsTemporary : 1;
55 /// IsUsed - True if this symbol has been used.
56 mutable unsigned IsUsed : 1;
58 private: // MCContext creates and uniques these.
59 friend class MCContext;
60 MCSymbol(StringRef name, bool isTemporary)
61 : Name(name), Section(0), Value(0),
62 IsTemporary(isTemporary), IsUsed(false) {}
64 MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
65 void operator=(const MCSymbol&); // DO NOT IMPLEMENT
67 /// getName - Get the symbol name.
68 StringRef getName() const { return Name; }
73 /// isTemporary - Check if this is an assembler temporary symbol.
74 bool isTemporary() const { return IsTemporary; }
76 /// isUsed - Check if this is used.
77 bool isUsed() const { return IsUsed; }
78 void setUsed(bool Value) const { IsUsed = Value; }
81 /// @name Associated Sections
84 /// isDefined - Check if this symbol is defined (i.e., it has an address).
86 /// Defined symbols are either absolute or in some section.
87 bool isDefined() const {
91 /// isInSection - Check if this symbol is defined in some section (i.e., it
92 /// is defined but not absolute).
93 bool isInSection() const {
94 return isDefined() && !isAbsolute();
97 /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
98 bool isUndefined() const {
102 /// isAbsolute - Check if this is an absolute symbol.
103 bool isAbsolute() const {
104 return Section == AbsolutePseudoSection;
107 /// getSection - Get the section associated with a defined, non-absolute
109 const MCSection &getSection() const {
110 assert(isInSection() && "Invalid accessor!");
114 /// setSection - Mark the symbol as defined in the section \arg S.
115 void setSection(const MCSection &S) { Section = &S; }
117 /// setUndefined - Mark the symbol as undefined.
118 void setUndefined() {
122 /// setAbsolute - Mark the symbol as absolute.
123 void setAbsolute() { Section = AbsolutePseudoSection; }
126 /// @name Variable Symbols
129 /// isVariable - Check if this is a variable symbol.
130 bool isVariable() const {
134 /// getValue() - Get the value for variable symbols.
135 const MCExpr *getVariableValue() const {
136 assert(isVariable() && "Invalid accessor!");
141 // AliasedSymbol() - If this is an alias (a = b), return the symbol
142 // we ultimately point to. For a non alias, this just returns the symbol
144 const MCSymbol &AliasedSymbol() const;
146 void setVariableValue(const MCExpr *Value);
150 /// print - Print the value to the stream \arg OS.
151 void print(raw_ostream &OS) const;
153 /// dump - Print the value to stderr.
157 inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
161 } // end namespace llvm