LLVM API Documentation

ValueSymbolTable.h

Go to the documentation of this file.
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 Module;
00027   
00028 /// This class provides a symbol table of name/value pairs. It is essentially
00029 /// a std::map<std::string,Value*> but has a controlled interface provided by
00030 /// LLVM as well as ensuring uniqueness of names.
00031 ///
00032 class ValueSymbolTable {
00033   friend class Value;
00034   friend class SymbolTableListTraits<Argument, Function>;
00035   friend class SymbolTableListTraits<BasicBlock, Function>;
00036   friend class SymbolTableListTraits<Instruction, BasicBlock>;
00037   friend class SymbolTableListTraits<Function, Module>;
00038   friend class SymbolTableListTraits<GlobalVariable, Module>;
00039   friend class SymbolTableListTraits<GlobalAlias, Module>;
00040 /// @name Types
00041 /// @{
00042 public:
00043   /// @brief A mapping of names to values.
00044   typedef StringMap<Value*> ValueMap;
00045 
00046   /// @brief An iterator over a ValueMap.
00047   typedef ValueMap::iterator iterator;
00048 
00049   /// @brief A const_iterator over a ValueMap.
00050   typedef ValueMap::const_iterator const_iterator;
00051 
00052 /// @}
00053 /// @name Constructors
00054 /// @{
00055 public:
00056 
00057   ValueSymbolTable() : vmap(0), LastUnique(0) {}
00058   ~ValueSymbolTable();
00059 
00060 /// @}
00061 /// @name Accessors
00062 /// @{
00063 public:
00064 
00065   /// This method finds the value with the given \p name in the
00066   /// the symbol table. 
00067   /// @returns the value associated with the \p name
00068   /// @brief Lookup a named Value.
00069   Value *lookup(const std::string &name) const;
00070   Value *lookup(const char *NameBegin, const char *NameEnd) const;
00071 
00072   /// @returns true iff the symbol table is empty
00073   /// @brief Determine if the symbol table is empty
00074   inline bool empty() const { return vmap.empty(); }
00075 
00076   /// @brief The number of name/type pairs is returned.
00077   inline unsigned size() const { return unsigned(vmap.size()); }
00078 
00079   /// This function can be used from the debugger to display the
00080   /// content of the symbol table while debugging.
00081   /// @brief Print out symbol table on stderr
00082   void dump() const;
00083 
00084 /// @}
00085 /// @name Iteration
00086 /// @{
00087 public:
00088   /// @brief Get an iterator that from the beginning of the symbol table.
00089   inline iterator begin() { return vmap.begin(); }
00090 
00091   /// @brief Get a const_iterator that from the beginning of the symbol table.
00092   inline const_iterator begin() const { return vmap.begin(); }
00093 
00094   /// @brief Get an iterator to the end of the symbol table.
00095   inline iterator end() { return vmap.end(); }
00096 
00097   /// @brief Get a const_iterator to the end of the symbol table.
00098   inline const_iterator end() const { return vmap.end(); }
00099   
00100 /// @}
00101 /// @name Mutators
00102 /// @{
00103 private:
00104   /// This method adds the provided value \p N to the symbol table.  The Value
00105   /// must have a name which is used to place the value in the symbol table. 
00106   /// If the inserted name conflicts, this renames the value.
00107   /// @brief Add a named value to the symbol table
00108   void reinsertValue(Value *V);
00109     
00110   /// createValueName - This method attempts to create a value name and insert
00111   /// it into the symbol table with the specified name.  If it conflicts, it
00112   /// auto-renames the name and returns that instead.
00113   ValueName *createValueName(const char *NameStart, unsigned NameLen, Value *V);
00114   
00115   /// This method removes a value from the symbol table.  It leaves the
00116   /// ValueName attached to the value, but it is no longer inserted in the
00117   /// symtab.
00118   void removeValueName(ValueName *V);
00119   
00120 /// @}
00121 /// @name Internal Data
00122 /// @{
00123 private:
00124   ValueMap vmap;                    ///< The map that holds the symbol table.
00125   mutable uint32_t LastUnique; ///< Counter for tracking unique names
00126 
00127 /// @}
00128 };
00129 
00130 } // End llvm namespace
00131 
00132 #endif



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.