LLVM API Documentation
00001 //===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the name/Value symbol table for LLVM. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_VALUE_SYMBOL_TABLE_H 00015 #define LLVM_VALUE_SYMBOL_TABLE_H 00016 00017 #include "llvm/Value.h" 00018 #include "llvm/ADT/StringMap.h" 00019 #include "llvm/Support/DataTypes.h" 00020 00021 namespace llvm { 00022 template<typename ValueSubClass, typename ItemParentClass> 00023 class SymbolTableListTraits; 00024 class BasicBlock; 00025 class Function; 00026 class NamedMDNode; 00027 class Module; 00028 class StringRef; 00029 00030 /// This class provides a symbol table of name/value pairs. It is essentially 00031 /// a std::map<std::string,Value*> but has a controlled interface provided by 00032 /// LLVM as well as ensuring uniqueness of names. 00033 /// 00034 class ValueSymbolTable { 00035 friend class Value; 00036 friend class SymbolTableListTraits<Argument, Function>; 00037 friend class SymbolTableListTraits<BasicBlock, Function>; 00038 friend class SymbolTableListTraits<Instruction, BasicBlock>; 00039 friend class SymbolTableListTraits<Function, Module>; 00040 friend class SymbolTableListTraits<GlobalVariable, Module>; 00041 friend class SymbolTableListTraits<GlobalAlias, Module>; 00042 friend class SymbolTableListTraits<NamedMDNode, Module>; 00043 /// @name Types 00044 /// @{ 00045 public: 00046 /// @brief A mapping of names to values. 00047 typedef StringMap<Value*> ValueMap; 00048 00049 /// @brief An iterator over a ValueMap. 00050 typedef ValueMap::iterator iterator; 00051 00052 /// @brief A const_iterator over a ValueMap. 00053 typedef ValueMap::const_iterator const_iterator; 00054 00055 /// @} 00056 /// @name Constructors 00057 /// @{ 00058 public: 00059 00060 ValueSymbolTable() : vmap(0), LastUnique(0) {} 00061 ~ValueSymbolTable(); 00062 00063 /// @} 00064 /// @name Accessors 00065 /// @{ 00066 public: 00067 00068 /// This method finds the value with the given \p Name in the 00069 /// the symbol table. 00070 /// @returns the value associated with the \p Name 00071 /// @brief Lookup a named Value. 00072 Value *lookup(const StringRef &Name) const { return vmap.lookup(Name); } 00073 00074 /// @returns true iff the symbol table is empty 00075 /// @brief Determine if the symbol table is empty 00076 inline bool empty() const { return vmap.empty(); } 00077 00078 /// @brief The number of name/type pairs is returned. 00079 inline unsigned size() const { return unsigned(vmap.size()); } 00080 00081 /// This function can be used from the debugger to display the 00082 /// content of the symbol table while debugging. 00083 /// @brief Print out symbol table on stderr 00084 void dump() const; 00085 00086 /// @} 00087 /// @name Iteration 00088 /// @{ 00089 public: 00090 /// @brief Get an iterator that from the beginning of the symbol table. 00091 inline iterator begin() { return vmap.begin(); } 00092 00093 /// @brief Get a const_iterator that from the beginning of the symbol table. 00094 inline const_iterator begin() const { return vmap.begin(); } 00095 00096 /// @brief Get an iterator to the end of the symbol table. 00097 inline iterator end() { return vmap.end(); } 00098 00099 /// @brief Get a const_iterator to the end of the symbol table. 00100 inline const_iterator end() const { return vmap.end(); } 00101 00102 /// @} 00103 /// @name Mutators 00104 /// @{ 00105 private: 00106 /// This method adds the provided value \p N to the symbol table. The Value 00107 /// must have a name which is used to place the value in the symbol table. 00108 /// If the inserted name conflicts, this renames the value. 00109 /// @brief Add a named value to the symbol table 00110 void reinsertValue(Value *V); 00111 00112 /// createValueName - This method attempts to create a value name and insert 00113 /// it into the symbol table with the specified name. If it conflicts, it 00114 /// auto-renames the name and returns that instead. 00115 ValueName *createValueName(const StringRef &Name, Value *V); 00116 00117 /// This method removes a value from the symbol table. It leaves the 00118 /// ValueName attached to the value, but it is no longer inserted in the 00119 /// symtab. 00120 void removeValueName(ValueName *V); 00121 00122 /// @} 00123 /// @name Internal Data 00124 /// @{ 00125 private: 00126 ValueMap vmap; ///< The map that holds the symbol table. 00127 mutable uint32_t LastUnique; ///< Counter for tracking unique names 00128 00129 /// @} 00130 }; 00131 00132 } // End llvm namespace 00133 00134 #endif