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 was developed by Reid Spencer based on the original SymbolTable.h
00006 // written by the LLVM research group and re-written by Reid Spencer.
00007 // It is distributed under the University of Illinois Open Source License. 
00008 // See LICENSE.TXT for details.
00009 //
00010 //===----------------------------------------------------------------------===//
00011 //
00012 // This file implements the name/Value symbol table for LLVM.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_VALUE_SYMBOL_TABLE_H
00017 #define LLVM_VALUE_SYMBOL_TABLE_H
00018 
00019 #include "llvm/Value.h"
00020 #include <map>
00021 
00022 namespace llvm {
00023 
00024 /// This class provides a symbol table of name/value pairs. It is essentially
00025 /// a std::map<std::string,Value*> but has a controlled interface provided by
00026 /// LLVM as well as ensuring uniqueness of names.
00027 ///
00028 class ValueSymbolTable {
00029 
00030 /// @name Types
00031 /// @{
00032 public:
00033 
00034   /// @brief A mapping of names to values.
00035   typedef std::map<const std::string, Value *> ValueMap;
00036 
00037   /// @brief An iterator over a ValueMap.
00038   typedef ValueMap::iterator iterator;
00039 
00040   /// @brief A const_iterator over a ValueMap.
00041   typedef ValueMap::const_iterator const_iterator;
00042 
00043 /// @}
00044 /// @name Constructors
00045 /// @{
00046 public:
00047 
00048   ValueSymbolTable() : LastUnique(0) {}
00049   ~ValueSymbolTable();
00050 
00051 /// @}
00052 /// @name Accessors
00053 /// @{
00054 public:
00055 
00056   /// This method finds the value with the given \p name in the
00057   /// the symbol table. 
00058   /// @returns the value associated with the \p name
00059   /// @brief Lookup a named Value.
00060   Value *lookup(const std::string &name) const;
00061 
00062   /// @returns true iff the symbol table is empty
00063   /// @brief Determine if the symbol table is empty
00064   inline bool empty() const { return vmap.empty(); }
00065 
00066   /// @brief The number of name/type pairs is returned.
00067   inline unsigned size() const { return unsigned(vmap.size()); }
00068 
00069   /// Given a base name, return a string that is either equal to it or
00070   /// derived from it that does not already occur in the symbol table
00071   /// for the specified type.
00072   /// @brief Get a name unique to this symbol table
00073   std::string getUniqueName(const std::string &BaseName) const;
00074 
00075   /// This function can be used from the debugger to display the
00076   /// content of the symbol table while debugging.
00077   /// @brief Print out symbol table on stderr
00078   void dump() const;
00079 
00080 /// @}
00081 /// @name Iteration
00082 /// @{
00083 public:
00084 
00085   /// @brief Get an iterator that from the beginning of the symbol table.
00086   inline iterator begin() { return vmap.begin(); }
00087 
00088   /// @brief Get a const_iterator that from the beginning of the symbol table.
00089   inline const_iterator begin() const { return vmap.begin(); }
00090 
00091   /// @brief Get an iterator to the end of the symbol table.
00092   inline iterator end() { return vmap.end(); }
00093 
00094   /// @brief Get a const_iterator to the end of the symbol table.
00095   inline const_iterator end() const { return vmap.end(); }
00096 
00097 /// @}
00098 /// @name Mutators
00099 /// @{
00100 public:
00101 
00102   /// This method will strip the symbol table of its names.
00103   /// @brief Strip the symbol table.
00104   bool strip();
00105 
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   /// @brief Add a named value to the symbol table
00109   void insert(Value *Val);
00110 
00111   /// This method removes a value from the symbol table. The name of the
00112   /// Value is extracted from \p Val and used to lookup the Value in the
00113   /// symbol table. If the Value is not in the symbol table, this method
00114   /// returns false.
00115   /// @returns true if \p Val was successfully erased, false otherwise
00116   /// @brief Remove a value from the symbol table.
00117   bool erase(Value* Val);
00118 
00119   /// Given a value with a non-empty name, remove its existing
00120   /// entry from the symbol table and insert a new one for Name.  This is
00121   /// equivalent to doing "remove(V), V->Name = Name, insert(V)".
00122   /// @brief Rename a value in the symbol table
00123   bool rename(Value *V, const std::string &Name);
00124 
00125 /// @}
00126 /// @name Internal Data
00127 /// @{
00128 private:
00129   ValueMap vmap;                    ///< The map that holds the symbol table.
00130   mutable uint32_t LastUnique; ///< Counter for tracking unique names
00131 
00132 /// @}
00133 
00134 };
00135 
00136 } // End llvm namespace
00137 
00138 #endif