Get MCSymbol out of the mangling business, and move all the logic
[oota-llvm.git] / include / llvm / MC / MCSymbol.h
1 //===- MCSymbol.h - Machine Code Symbols ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the MCSymbol class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSYMBOL_H
15 #define LLVM_MC_MCSYMBOL_H
16
17 #include <string>
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/System/DataTypes.h"
20
21 namespace llvm {
22   class MCAsmInfo;
23   class MCExpr;
24   class MCSection;
25   class MCContext;
26   class raw_ostream;
27
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.
31   ///
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.  
35   /// 
36   class MCSymbol {
37     // Special sentinal value for the absolute pseudo section.
38     //
39     // FIXME: Use a PointerInt wrapper for this?
40     static const MCSection *AbsolutePseudoSection;
41
42     /// Name - The name of the symbol.
43     std::string Name;
44
45     /// Section - The section the symbol is defined in. This is null for
46     /// undefined symbols, and the special AbsolutePseudoSection value for
47     /// absolute symbols.
48     const MCSection *Section;
49
50     /// Value - If non-null, the value for a variable symbol.
51     const MCExpr *Value;
52
53     /// IsTemporary - True if this is an assembler temporary label, which
54     /// typically does not survive in the .o file's symbol table.  Usually
55     /// "Lfoo" or ".foo".
56     unsigned IsTemporary : 1;
57     
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) {}
62
63     MCSymbol(const MCSymbol&);       // DO NOT IMPLEMENT
64     void operator=(const MCSymbol&); // DO NOT IMPLEMENT
65   public:
66     /// getName - Get the symbol name.
67     const std::string &getName() const { return Name; }
68
69     /// @name Symbol Type
70     /// @{
71
72     /// isTemporary - Check if this is an assembler temporary symbol.
73     bool isTemporary() const {
74       return IsTemporary;
75     }
76
77     /// @}
78     /// @name Associated Sections
79     /// @{
80
81     /// isDefined - Check if this symbol is defined (i.e., it has an address).
82     ///
83     /// Defined symbols are either absolute or in some section.
84     bool isDefined() const {
85       return Section != 0;
86     }
87
88     /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
89     bool isUndefined() const {
90       return !isDefined();
91     }
92
93     /// isAbsolute - Check if this this is an absolute symbol.
94     bool isAbsolute() const {
95       return Section == AbsolutePseudoSection;
96     }
97
98     /// getSection - Get the section associated with a defined, non-absolute
99     /// symbol.
100     const MCSection &getSection() const {
101       assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
102       return *Section;
103     }
104
105     /// setSection - Mark the symbol as defined in the section \arg S.
106     void setSection(const MCSection &S) { Section = &S; }
107
108     /// setUndefined - Mark the symbol as undefined.
109     void setUndefined() {
110       Section = 0;
111     }
112
113     /// setAbsolute - Mark the symbol as absolute.
114     void setAbsolute() { Section = AbsolutePseudoSection; }
115
116     /// @}
117     /// @name Variable Symbols
118     /// @{
119
120     /// isVariable - Check if this is a variable symbol.
121     bool isVariable() const {
122       return Value != 0;
123     }
124
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; }
128
129     void setValue(const MCExpr *Value) {
130       this->Value = Value;
131     }
132
133     /// @}
134
135     /// print - Print the value to the stream \arg OS.
136     void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
137
138     /// dump - Print the value to stderr.
139     void dump() const;
140   };
141
142 } // end namespace llvm
143
144 #endif