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