2006-01-10 09:51:48 +00:00
|
|
|
//===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-01-10 09:51:48 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the name/Value symbol table for LLVM.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_VALUE_SYMBOL_TABLE_H
|
|
|
|
#define LLVM_VALUE_SYMBOL_TABLE_H
|
|
|
|
|
|
|
|
#include "llvm/Value.h"
|
2007-02-12 05:18:08 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2007-05-18 07:07:05 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-04-17 03:26:42 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
2007-02-07 06:06:24 +00:00
|
|
|
class SymbolTableListTraits;
|
|
|
|
class BasicBlock;
|
|
|
|
class Function;
|
|
|
|
class Module;
|
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// This class provides a symbol table of name/value pairs. It is essentially
|
|
|
|
/// a std::map<std::string,Value*> but has a controlled interface provided by
|
|
|
|
/// LLVM as well as ensuring uniqueness of names.
|
|
|
|
///
|
|
|
|
class ValueSymbolTable {
|
2007-02-07 06:06:24 +00:00
|
|
|
friend class Value;
|
2007-04-17 03:26:42 +00:00
|
|
|
friend class SymbolTableListTraits<Argument, Function>;
|
|
|
|
friend class SymbolTableListTraits<BasicBlock, Function>;
|
|
|
|
friend class SymbolTableListTraits<Instruction, BasicBlock>;
|
|
|
|
friend class SymbolTableListTraits<Function, Module>;
|
|
|
|
friend class SymbolTableListTraits<GlobalVariable, Module>;
|
2007-04-25 14:27:10 +00:00
|
|
|
friend class SymbolTableListTraits<GlobalAlias, Module>;
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @name Types
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief A mapping of names to values.
|
2007-02-12 05:18:08 +00:00
|
|
|
typedef StringMap<Value*> ValueMap;
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @brief An iterator over a ValueMap.
|
|
|
|
typedef ValueMap::iterator iterator;
|
|
|
|
|
|
|
|
/// @brief A const_iterator over a ValueMap.
|
|
|
|
typedef ValueMap::const_iterator const_iterator;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
2007-04-04 00:30:49 +00:00
|
|
|
ValueSymbolTable() : vmap(0), LastUnique(0) {}
|
2006-01-10 09:51:48 +00:00
|
|
|
~ValueSymbolTable();
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// This method finds the value with the given \p name in the
|
|
|
|
/// the symbol table.
|
|
|
|
/// @returns the value associated with the \p name
|
|
|
|
/// @brief Lookup a named Value.
|
|
|
|
Value *lookup(const std::string &name) const;
|
2008-06-27 21:09:10 +00:00
|
|
|
Value *lookup(const char *NameBegin, const char *NameEnd) const;
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @returns true iff the symbol table is empty
|
|
|
|
/// @brief Determine if the symbol table is empty
|
|
|
|
inline bool empty() const { return vmap.empty(); }
|
|
|
|
|
|
|
|
/// @brief The number of name/type pairs is returned.
|
|
|
|
inline unsigned size() const { return unsigned(vmap.size()); }
|
|
|
|
|
|
|
|
/// This function can be used from the debugger to display the
|
|
|
|
/// content of the symbol table while debugging.
|
|
|
|
/// @brief Print out symbol table on stderr
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Iteration
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief Get an iterator that from the beginning of the symbol table.
|
|
|
|
inline iterator begin() { return vmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator that from the beginning of the symbol table.
|
|
|
|
inline const_iterator begin() const { return vmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get an iterator to the end of the symbol table.
|
|
|
|
inline iterator end() { return vmap.end(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator to the end of the symbol table.
|
|
|
|
inline const_iterator end() const { return vmap.end(); }
|
2007-02-12 05:18:08 +00:00
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
2007-02-07 06:06:24 +00:00
|
|
|
private:
|
2006-01-10 09:51:48 +00:00
|
|
|
/// This method adds the provided value \p N to the symbol table. The Value
|
|
|
|
/// must have a name which is used to place the value in the symbol table.
|
2007-02-12 05:18:08 +00:00
|
|
|
/// If the inserted name conflicts, this renames the value.
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @brief Add a named value to the symbol table
|
2007-02-12 05:18:08 +00:00
|
|
|
void reinsertValue(Value *V);
|
|
|
|
|
|
|
|
/// createValueName - This method attempts to create a value name and insert
|
|
|
|
/// it into the symbol table with the specified name. If it conflicts, it
|
|
|
|
/// auto-renames the name and returns that instead.
|
|
|
|
ValueName *createValueName(const char *NameStart, unsigned NameLen, Value *V);
|
|
|
|
|
|
|
|
/// This method removes a value from the symbol table. It leaves the
|
|
|
|
/// ValueName attached to the value, but it is no longer inserted in the
|
|
|
|
/// symtab.
|
|
|
|
void removeValueName(ValueName *V);
|
2007-02-07 06:13:49 +00:00
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Internal Data
|
|
|
|
/// @{
|
|
|
|
private:
|
|
|
|
ValueMap vmap; ///< The map that holds the symbol table.
|
2006-05-31 20:40:36 +00:00
|
|
|
mutable uint32_t LastUnique; ///< Counter for tracking unique names
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|