37a2755328f02eafcd8cab9721f729e36c591d06
[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/Support/DataTypes.h"
20
21 namespace llvm {
22   class MCSection;
23   class MCContext;
24   class raw_ostream;
25
26   /// MCSymbol - Instances of this class represent a symbol name in the MC file,
27   /// and MCSymbols are created and unique'd by the MCContext class.
28   ///
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.  
32   /// 
33   class MCSymbol {
34     // Special sentinal value for the absolute pseudo section.
35     //
36     // FIXME: Use a PointerInt wrapper for this?
37     static const MCSection *AbsolutePseudoSection;
38
39     /// Name - The name of the symbol.
40     std::string Name;
41
42     /// Section - The section the symbol is defined in. This is null for
43     /// undefined symbols, and the special AbsolutePseudoSection value for
44     /// absolute symbols.
45     const MCSection *Section;
46
47     /// IsTemporary - True if this is an assembler temporary label, which
48     /// typically does not survive in the .o file's symbol table.  Usually
49     /// "Lfoo" or ".foo".
50     unsigned IsTemporary : 1;
51
52   private:  // MCContext creates and uniques these.
53     friend class MCContext;
54     MCSymbol(const StringRef &_Name, bool _IsTemporary) 
55       : Name(_Name), Section(0), IsTemporary(_IsTemporary) {}
56     
57     MCSymbol(const MCSymbol&);       // DO NOT IMPLEMENT
58     void operator=(const MCSymbol&); // DO NOT IMPLEMENT
59   public:
60     /// getName - Get the symbol name.
61     const std::string &getName() const { return Name; }
62
63     /// @name Symbol Type
64     /// @{
65
66     /// isDefined - Check if this symbol is defined (i.e., it has an address).
67     ///
68     /// Defined symbols are either absolute or in some section.
69     bool isDefined() const {
70       return Section != 0;
71     }
72
73     /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
74     bool isUndefined() const {
75       return !isDefined();
76     }
77
78     /// isAbsolute - Check if this this is an absolute symbol.
79     bool isAbsolute() const {
80       return Section == AbsolutePseudoSection;
81     }
82
83     /// getSection - Get the section associated with a defined, non-absolute
84     /// symbol.
85     const MCSection &getSection() const {
86       assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
87       return *Section;
88     }
89
90     /// setSection - Mark the symbol as defined in the section \arg S.
91     void setSection(const MCSection &S) { Section = &S; }
92
93     /// setUndefined - Mark the symbol as undefined.
94     void setUndefined() {
95       Section = 0;
96     }
97
98     /// setAbsolute - Mark the symbol as absolute.
99     void setAbsolute() { Section = AbsolutePseudoSection; }
100
101     /// @}
102
103     /// print - Print the value to the stream \arg OS.
104     void print(raw_ostream &OS) const;
105
106     /// dump - Print the value to stderr.
107     void dump() const;
108   };
109
110 } // end namespace llvm
111
112 #endif