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.
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 private: // MCContext creates and uniques these.
57 friend class MCContext;
58 MCSymbol(StringRef name, bool isTemporary)
59 : Name(name), Section(0), Value(0), IsTemporary(isTemporary) {}
61 MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
62 void operator=(const MCSymbol&); // DO NOT IMPLEMENT
64 /// getName - Get the symbol name.
65 StringRef getName() const { return Name; }
70 /// isTemporary - Check if this is an assembler temporary symbol.
71 bool isTemporary() const {
76 /// @name Associated Sections
79 /// isDefined - Check if this symbol is defined (i.e., it has an address).
81 /// Defined symbols are either absolute or in some section.
82 bool isDefined() const {
86 /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
87 bool isUndefined() const {
91 /// isAbsolute - Check if this is an absolute symbol.
92 bool isAbsolute() const {
93 return Section == AbsolutePseudoSection;
96 /// getSection - Get the section associated with a defined, non-absolute
98 const MCSection &getSection() const {
99 assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
103 /// setSection - Mark the symbol as defined in the section \arg S.
104 void setSection(const MCSection &S) { Section = &S; }
106 /// setUndefined - Mark the symbol as undefined.
107 void setUndefined() {
111 /// setAbsolute - Mark the symbol as absolute.
112 void setAbsolute() { Section = AbsolutePseudoSection; }
115 /// @name Variable Symbols
118 /// isVariable - Check if this is a variable symbol.
119 bool isVariable() const {
123 /// getValue() - Get the value for variable symbols, or null if the symbol
124 /// is not a variable.
125 const MCExpr *getValue() const { return Value; }
127 void setValue(const MCExpr *Value) {
133 /// print - Print the value to the stream \arg OS.
134 void print(raw_ostream &OS) const;
136 /// dump - Print the value to stderr.
140 inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
144 } // end namespace llvm