Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
5.0 KiB

  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. #ifndef LLVM_MC_MCSYMBOL_H
  14. #define LLVM_MC_MCSYMBOL_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Support/Compiler.h"
  17. namespace llvm {
  18. class MCExpr;
  19. class MCSection;
  20. class MCContext;
  21. class raw_ostream;
  22. /// MCSymbol - Instances of this class represent a symbol name in the MC file,
  23. /// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
  24. /// should only be constructed with valid names for the object file.
  25. ///
  26. /// If the symbol is defined/emitted into the current translation unit, the
  27. /// Section member is set to indicate what section it lives in. Otherwise, if
  28. /// it is a reference to an external entity, it has a null section.
  29. class MCSymbol {
  30. // Special sentinal value for the absolute pseudo section.
  31. //
  32. // FIXME: Use a PointerInt wrapper for this?
  33. static const MCSection *AbsolutePseudoSection;
  34. /// Name - The name of the symbol. The referred-to string data is actually
  35. /// held by the StringMap that lives in MCContext.
  36. StringRef Name;
  37. /// Section - The section the symbol is defined in. This is null for
  38. /// undefined symbols, and the special AbsolutePseudoSection value for
  39. /// absolute symbols.
  40. const MCSection *Section;
  41. /// Value - If non-null, the value for a variable symbol.
  42. const MCExpr *Value;
  43. /// IsTemporary - True if this is an assembler temporary label, which
  44. /// typically does not survive in the .o file's symbol table. Usually
  45. /// "Lfoo" or ".foo".
  46. unsigned IsTemporary : 1;
  47. /// IsUsed - True if this symbol has been used.
  48. mutable unsigned IsUsed : 1;
  49. private: // MCContext creates and uniques these.
  50. friend class MCExpr;
  51. friend class MCContext;
  52. MCSymbol(StringRef name, bool isTemporary)
  53. : Name(name), Section(0), Value(0),
  54. IsTemporary(isTemporary), IsUsed(false) {}
  55. MCSymbol(const MCSymbol&) LLVM_DELETED_FUNCTION;
  56. void operator=(const MCSymbol&) LLVM_DELETED_FUNCTION;
  57. public:
  58. /// getName - Get the symbol name.
  59. StringRef getName() const { return Name; }
  60. /// @name Accessors
  61. /// @{
  62. /// isTemporary - Check if this is an assembler temporary symbol.
  63. bool isTemporary() const { return IsTemporary; }
  64. /// isUsed - Check if this is used.
  65. bool isUsed() const { return IsUsed; }
  66. void setUsed(bool Value) const { IsUsed = Value; }
  67. /// @}
  68. /// @name Associated Sections
  69. /// @{
  70. /// isDefined - Check if this symbol is defined (i.e., it has an address).
  71. ///
  72. /// Defined symbols are either absolute or in some section.
  73. bool isDefined() const {
  74. return Section != 0;
  75. }
  76. /// isInSection - Check if this symbol is defined in some section (i.e., it
  77. /// is defined but not absolute).
  78. bool isInSection() const {
  79. return isDefined() && !isAbsolute();
  80. }
  81. /// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
  82. bool isUndefined() const {
  83. return !isDefined();
  84. }
  85. /// isAbsolute - Check if this is an absolute symbol.
  86. bool isAbsolute() const {
  87. return Section == AbsolutePseudoSection;
  88. }
  89. /// getSection - Get the section associated with a defined, non-absolute
  90. /// symbol.
  91. const MCSection &getSection() const {
  92. assert(isInSection() && "Invalid accessor!");
  93. return *Section;
  94. }
  95. /// setSection - Mark the symbol as defined in the section \p S.
  96. void setSection(const MCSection &S) { Section = &S; }
  97. /// setUndefined - Mark the symbol as undefined.
  98. void setUndefined() {
  99. Section = 0;
  100. }
  101. /// setAbsolute - Mark the symbol as absolute.
  102. void setAbsolute() { Section = AbsolutePseudoSection; }
  103. /// @}
  104. /// @name Variable Symbols
  105. /// @{
  106. /// isVariable - Check if this is a variable symbol.
  107. bool isVariable() const {
  108. return Value != 0;
  109. }
  110. /// getVariableValue() - Get the value for variable symbols.
  111. const MCExpr *getVariableValue() const {
  112. assert(isVariable() && "Invalid accessor!");
  113. IsUsed = true;
  114. return Value;
  115. }
  116. // AliasedSymbol() - If this is an alias (a = b), return the symbol
  117. // we ultimately point to. For a non alias, this just returns the symbol
  118. // itself.
  119. const MCSymbol &AliasedSymbol() const;
  120. void setVariableValue(const MCExpr *Value);
  121. /// @}
  122. /// print - Print the value to the stream \p OS.
  123. void print(raw_ostream &OS) const;
  124. /// dump - Print the value to stderr.
  125. void dump() const;
  126. };
  127. inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
  128. Sym.print(OS);
  129. return OS;
  130. }
  131. } // end namespace llvm
  132. #endif