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
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/System/DataTypes.h"
28 /// MCSymbol - Instances of this class represent a symbol name in the MC file,
29 /// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
30 /// should only be constructed with valid names for the object file.
32 /// If the symbol is defined/emitted into the current translation unit, the
33 /// Section member is set to indicate what section it lives in. Otherwise, if
34 /// it is a reference to an external entity, it has a null section.
37 // Special sentinal value for the absolute pseudo section.
39 // FIXME: Use a PointerInt wrapper for this?
40 static const MCSection *AbsolutePseudoSection;
42 /// Name - The name of the symbol.
45 /// Section - The section the symbol is defined in. This is null for
46 /// undefined symbols, and the special AbsolutePseudoSection value for
48 const MCSection *Section;
50 /// Value - If non-null, the value for a variable symbol.
53 /// IsTemporary - True if this is an assembler temporary label, which
54 /// typically does not survive in the .o file's symbol table. Usually
56 unsigned IsTemporary : 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), IsTemporary(_IsTemporary) {}
63 MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
64 void operator=(const MCSymbol&); // DO NOT IMPLEMENT
66 /// getName - Get the symbol name.
67 const std::string &getName() const { return Name; }
72 /// isTemporary - Check if this is an assembler temporary symbol.
73 bool isTemporary() const {
78 /// @name Associated Sections
81 /// isDefined - Check if this symbol is defined (i.e., it has an address).
83 /// Defined symbols are either absolute or in some section.
84 bool isDefined() const {
88 /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
89 bool isUndefined() const {
93 /// isAbsolute - Check if this this is an absolute symbol.
94 bool isAbsolute() const {
95 return Section == AbsolutePseudoSection;
98 /// getSection - Get the section associated with a defined, non-absolute
100 const MCSection &getSection() const {
101 assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
105 /// setSection - Mark the symbol as defined in the section \arg S.
106 void setSection(const MCSection &S) { Section = &S; }
108 /// setUndefined - Mark the symbol as undefined.
109 void setUndefined() {
113 /// setAbsolute - Mark the symbol as absolute.
114 void setAbsolute() { Section = AbsolutePseudoSection; }
117 /// @name Variable Symbols
120 /// isVariable - Check if this is a variable symbol.
121 bool isVariable() const {
125 /// getValue() - Get the value for variable symbols, or null if the symbol
126 /// is not a variable.
127 const MCExpr *getValue() const { return Value; }
129 void setValue(const MCExpr *Value) {
135 /// print - Print the value to the stream \arg OS.
136 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
138 /// dump - Print the value to stderr.
142 } // end namespace llvm