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.

133 lines
4.1 KiB

  1. //===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- 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 implements the name/Value symbol table for LLVM.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_VALUE_SYMBOL_TABLE_H
  14. #define LLVM_VALUE_SYMBOL_TABLE_H
  15. #include "llvm/Value.h"
  16. #include "llvm/ADT/StringMap.h"
  17. #include "llvm/Support/DataTypes.h"
  18. namespace llvm {
  19. template<typename ValueSubClass, typename ItemParentClass>
  20. class SymbolTableListTraits;
  21. class BasicBlock;
  22. class Function;
  23. class NamedMDNode;
  24. class Module;
  25. class StringRef;
  26. /// This class provides a symbol table of name/value pairs. It is essentially
  27. /// a std::map<std::string,Value*> but has a controlled interface provided by
  28. /// LLVM as well as ensuring uniqueness of names.
  29. ///
  30. class ValueSymbolTable {
  31. friend class Value;
  32. friend class SymbolTableListTraits<Argument, Function>;
  33. friend class SymbolTableListTraits<BasicBlock, Function>;
  34. friend class SymbolTableListTraits<Instruction, BasicBlock>;
  35. friend class SymbolTableListTraits<Function, Module>;
  36. friend class SymbolTableListTraits<GlobalVariable, Module>;
  37. friend class SymbolTableListTraits<GlobalAlias, Module>;
  38. /// @name Types
  39. /// @{
  40. public:
  41. /// @brief A mapping of names to values.
  42. typedef StringMap<Value*> ValueMap;
  43. /// @brief An iterator over a ValueMap.
  44. typedef ValueMap::iterator iterator;
  45. /// @brief A const_iterator over a ValueMap.
  46. typedef ValueMap::const_iterator const_iterator;
  47. /// @}
  48. /// @name Constructors
  49. /// @{
  50. public:
  51. ValueSymbolTable() : vmap(0), LastUnique(0) {}
  52. ~ValueSymbolTable();
  53. /// @}
  54. /// @name Accessors
  55. /// @{
  56. public:
  57. /// This method finds the value with the given \p Name in the
  58. /// the symbol table.
  59. /// @returns the value associated with the \p Name
  60. /// @brief Lookup a named Value.
  61. Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
  62. /// @returns true iff the symbol table is empty
  63. /// @brief Determine if the symbol table is empty
  64. inline bool empty() const { return vmap.empty(); }
  65. /// @brief The number of name/type pairs is returned.
  66. inline unsigned size() const { return unsigned(vmap.size()); }
  67. /// This function can be used from the debugger to display the
  68. /// content of the symbol table while debugging.
  69. /// @brief Print out symbol table on stderr
  70. void dump() const;
  71. /// @}
  72. /// @name Iteration
  73. /// @{
  74. public:
  75. /// @brief Get an iterator that from the beginning of the symbol table.
  76. inline iterator begin() { return vmap.begin(); }
  77. /// @brief Get a const_iterator that from the beginning of the symbol table.
  78. inline const_iterator begin() const { return vmap.begin(); }
  79. /// @brief Get an iterator to the end of the symbol table.
  80. inline iterator end() { return vmap.end(); }
  81. /// @brief Get a const_iterator to the end of the symbol table.
  82. inline const_iterator end() const { return vmap.end(); }
  83. /// @}
  84. /// @name Mutators
  85. /// @{
  86. private:
  87. /// This method adds the provided value \p N to the symbol table. The Value
  88. /// must have a name which is used to place the value in the symbol table.
  89. /// If the inserted name conflicts, this renames the value.
  90. /// @brief Add a named value to the symbol table
  91. void reinsertValue(Value *V);
  92. /// createValueName - This method attempts to create a value name and insert
  93. /// it into the symbol table with the specified name. If it conflicts, it
  94. /// auto-renames the name and returns that instead.
  95. ValueName *createValueName(StringRef Name, Value *V);
  96. /// This method removes a value from the symbol table. It leaves the
  97. /// ValueName attached to the value, but it is no longer inserted in the
  98. /// symtab.
  99. void removeValueName(ValueName *V);
  100. /// @}
  101. /// @name Internal Data
  102. /// @{
  103. private:
  104. ValueMap vmap; ///< The map that holds the symbol table.
  105. mutable uint32_t LastUnique; ///< Counter for tracking unique names
  106. /// @}
  107. };
  108. } // End llvm namespace
  109. #endif