MCSymbol.h revision 8906ff1b9dfde28f1ff00706643ca10843b26e01
1827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//===- MCSymbol.h - Machine Code Symbols ------------------------*- C++ -*-===//
2827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//
3827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//                     The LLVM Compiler Infrastructure
4827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//
5827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes// This file is distributed under the University of Illinois Open Source
6827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes// License. See LICENSE.TXT for details.
7827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//
8827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//===----------------------------------------------------------------------===//
9827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//
10827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes// This file contains the declaration of the MCSymbol class.
11827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//
12827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes//===----------------------------------------------------------------------===//
13827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
14827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes#ifndef LLVM_MC_MCSYMBOL_H
15827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes#define LLVM_MC_MCSYMBOL_H
16827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
17827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes#include <string>
18827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes#include "llvm/ADT/StringRef.h"
19827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes#include "llvm/Support/DataTypes.h"
20827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
21827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughesnamespace llvm {
22827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  class MCSection;
23827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  class MCContext;
24827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  class raw_ostream;
25827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
26827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  /// MCSymbol - Instances of this class represent a symbol name in the MC file,
27827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  /// and MCSymbols are created and unique'd by the MCContext class.
28827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  ///
29827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  /// If the symbol is defined/emitted into the current translation unit, the
30827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  /// Section member is set to indicate what section it lives in.  Otherwise, if
31827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  /// it is a reference to an external entity, it has a null section.
32827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  ///
33827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  class MCSymbol {
34827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    // Special sentinal value for the absolute pseudo section.
35827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    //
36827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    // FIXME: Use a PointerInt wrapper for this?
37827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    static const MCSection *AbsolutePseudoSection;
38827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
39827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// Name - The name of the symbol.
40827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    std::string Name;
41827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
42827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// Section - The section the symbol is defined in. This is null for
43827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// undefined symbols, and the special AbsolutePseudoSection value for
44827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// absolute symbols.
45827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    const MCSection *Section;
46827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
47827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// IsTemporary - True if this is an assembler temporary label, which
48827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// typically does not survive in the .o file's symbol table.  Usually
49827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    /// "Lfoo" or ".foo".
50827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    unsigned IsTemporary : 1;
51827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes
52827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes  private:  // MCContext creates and uniques these.
53827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    friend class MCContext;
54827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes    MCSymbol(const StringRef &_Name, bool _IsTemporary)
55827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes      : Name(_Name), Section(0),
56827283714cf6f0ff11f3b46a98203cb3c8fd920bElliott Hughes        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 Location Functions
65    /// @{
66
67    /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
68    bool isUndefined() const {
69      return Section == 0;
70    }
71
72    /// isAbsolute - Check if this this is an absolute symbol.
73    bool isAbsolute() const {
74      return Section == AbsolutePseudoSection;
75    }
76
77    /// getSection - Get the section associated with a defined, non-absolute
78    /// symbol.
79    const MCSection &getSection() const {
80      assert(!isUndefined() && !isAbsolute() && "Invalid accessor!");
81      return *Section;
82    }
83
84    /// setSection - Mark the symbol as defined in the section \arg S.
85    void setSection(const MCSection &S) { Section = &S; }
86
87    /// setUndefined - Mark the symbol as undefined.
88    void setUndefined() {
89      Section = 0;
90    }
91
92    /// setAbsolute - Mark the symbol as absolute.
93    void setAbsolute() { Section = AbsolutePseudoSection; }
94
95    /// @}
96
97    /// print - Print the value to the stream \arg OS.
98    void print(raw_ostream &OS) const;
99
100    /// dump - Print the value to stderr.
101    void dump() const;
102  };
103
104} // end namespace llvm
105
106#endif
107