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.
31 /// If the symbol is defined/emitted into the current translation unit, the
32 /// Section member is set to indicate what section it lives in. Otherwise, if
33 /// it is a reference to an external entity, it has a null section.
36 // Special sentinal value for the absolute pseudo section.
38 // FIXME: Use a PointerInt wrapper for this?
39 static const MCSection *AbsolutePseudoSection;
41 /// Name - The name of the symbol.
44 /// Section - The section the symbol is defined in. This is null for
45 /// undefined symbols, and the special AbsolutePseudoSection value for
47 const MCSection *Section;
49 /// Value - If non-null, the value for a variable symbol.
52 /// IsTemporary - True if this is an assembler temporary label, which
53 /// typically does not survive in the .o file's symbol table. Usually
55 unsigned IsTemporary : 1;
57 private: // MCContext creates and uniques these.
58 friend class MCContext;
59 MCSymbol(const StringRef &_Name, bool _IsTemporary)
60 : Name(_Name), Section(0), Value(0), IsTemporary(_IsTemporary) {}
62 MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
63 void operator=(const MCSymbol&); // DO NOT IMPLEMENT
65 /// getName - Get the symbol name.
66 const std::string &getName() const { return Name; }
71 /// isTemporary - Check if this is an assembler temporary symbol.
72 bool isTemporary() const {
77 /// @name Associated Sections
80 /// isDefined - Check if this symbol is defined (i.e., it has an address).
82 /// Defined symbols are either absolute or in some section.
83 bool isDefined() const {
87 /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
88 bool isUndefined() const {
92 /// isAbsolute - Check if this this is an absolute symbol.
93 bool isAbsolute() const {
94 return Section == AbsolutePseudoSection;
97 /// getSection - Get the section associated with a defined, non-absolute
99 const MCSection &getSection() const {
100 assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
104 /// setSection - Mark the symbol as defined in the section \arg S.
105 void setSection(const MCSection &S) { Section = &S; }
107 /// setUndefined - Mark the symbol as undefined.
108 void setUndefined() {
112 /// setAbsolute - Mark the symbol as absolute.
113 void setAbsolute() { Section = AbsolutePseudoSection; }
116 /// @name Variable Symbols
119 /// isVariable - Check if this is a variable symbol.
120 bool isVariable() const {
124 /// getValue() - Get the value for variable symbols, or null if the symbol
125 /// is not a variable.
126 const MCExpr *getValue() const { return Value; }
128 void setValue(const MCExpr *Value) {
134 /// print - Print the value to the stream \arg OS.
135 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
137 /// dump - Print the value to stderr.
141 } // end namespace llvm