2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/SymbolTable.h - Implement a type plane'd symtab ----*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2003-10-23 04:01:49 +00:00
|
|
|
// This file implements a symbol table that has planes broken up by type.
|
2001-06-06 20:29:01 +00:00
|
|
|
// Identical types may have overlapping symbol names as long as they are
|
|
|
|
// distinct.
|
|
|
|
//
|
|
|
|
// Note that this implements a chained symbol table. If a name being 'lookup'd
|
|
|
|
// isn't found in the current symbol table, then the parent symbol table is
|
|
|
|
// searched.
|
|
|
|
//
|
|
|
|
// This chaining behavior does NOT affect iterators though: only the lookup
|
2003-08-23 23:15:10 +00:00
|
|
|
// method.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYMBOL_TABLE_H
|
|
|
|
#define LLVM_SYMBOL_TABLE_H
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
#include "llvm/Value.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include <map>
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
class SymbolTable : public AbstractTypeUser,
|
2002-01-20 22:54:45 +00:00
|
|
|
public std::map<const Type *,
|
|
|
|
std::map<const std::string, Value *> > {
|
2001-10-13 06:17:50 +00:00
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
typedef std::map<const std::string, Value *> VarMap;
|
|
|
|
typedef std::map<const Type *, VarMap> super;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
typedef VarMap::iterator type_iterator;
|
|
|
|
typedef VarMap::const_iterator type_const_iterator;
|
|
|
|
|
2003-11-09 19:39:48 +00:00
|
|
|
inline SymbolTable() : InternallyInconsistent(false), LastUnique(0) {}
|
2001-06-06 20:29:01 +00:00
|
|
|
~SymbolTable();
|
|
|
|
|
|
|
|
// lookup - Returns null on failure...
|
2003-12-31 07:08:19 +00:00
|
|
|
Value *lookup(const Type *Ty, const std::string &name) const;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
// insert - Add named definition to the symbol table...
|
2001-09-07 16:21:36 +00:00
|
|
|
inline void insert(Value *N) {
|
|
|
|
assert(N->hasName() && "Value must be named to go into symbol table!");
|
2001-10-22 04:55:44 +00:00
|
|
|
insertEntry(N->getName(), N->getType(), N);
|
2001-09-07 16:21:36 +00:00
|
|
|
}
|
|
|
|
|
2003-01-30 20:54:03 +00:00
|
|
|
void remove(Value *N);
|
|
|
|
Value *type_remove(const type_iterator &It) {
|
|
|
|
return removeEntry(find(It->second->getType()), It);
|
|
|
|
}
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
// insert - Insert a constant or type into the symbol table with the specified
|
|
|
|
// name... There can be a many to one mapping between names and
|
|
|
|
// (constant/type)s.
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
inline void insert(const std::string &Name, Value *V) {
|
2001-12-03 22:26:30 +00:00
|
|
|
assert((isa<Type>(V) || isa<Constant>(V)) &&
|
2001-09-07 16:21:36 +00:00
|
|
|
"Can only insert types and constants here!");
|
2001-10-22 04:55:44 +00:00
|
|
|
insertEntry(Name, V->getType(), V);
|
2001-09-07 16:21:36 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-01-30 20:54:03 +00:00
|
|
|
/// remove - Remove a constant or type from the symbol table with the
|
|
|
|
/// specified name.
|
|
|
|
Value *remove(const std::string &Name, Value *V) {
|
|
|
|
iterator TI = find(V->getType());
|
|
|
|
return removeEntry(TI, TI->second.find(Name));
|
2001-10-23 01:53:01 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-06-25 07:31:05 +00:00
|
|
|
// getUniqueName - Given a base name, return a string that is either equal to
|
|
|
|
// it (or derived from it) that does not already occur in the symbol table for
|
|
|
|
// the specified type.
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
std::string getUniqueName(const Type *Ty, const std::string &BaseName);
|
2001-06-25 07:31:05 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
inline unsigned type_size(const Type *TypeID) const {
|
|
|
|
return find(TypeID)->second.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that type_begin / type_end only work if you know that an element of
|
|
|
|
// TypeID is already in the symbol table!!!
|
|
|
|
//
|
|
|
|
inline type_iterator type_begin(const Type *TypeID) {
|
|
|
|
return find(TypeID)->second.begin();
|
|
|
|
}
|
|
|
|
inline type_const_iterator type_begin(const Type *TypeID) const {
|
|
|
|
return find(TypeID)->second.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline type_iterator type_end(const Type *TypeID) {
|
|
|
|
return find(TypeID)->second.end();
|
|
|
|
}
|
|
|
|
inline type_const_iterator type_end(const Type *TypeID) const {
|
|
|
|
return find(TypeID)->second.end();
|
|
|
|
}
|
2001-09-07 16:21:36 +00:00
|
|
|
|
2001-10-03 19:28:15 +00:00
|
|
|
void dump() const; // Debug method, print out symbol table
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
private:
|
2001-10-23 02:32:45 +00:00
|
|
|
// InternallyInconsistent - There are times when the symbol table is
|
|
|
|
// internally inconsistent with the rest of the program. In this one case, a
|
|
|
|
// value exists with a Name, and it's not in the symbol table. When we call
|
|
|
|
// V->setName(""), it tries to remove itself from the symbol table and dies.
|
|
|
|
// We know this is happening, and so if the flag InternallyInconsistent is
|
|
|
|
// set, removal from the symbol table is a noop.
|
|
|
|
//
|
|
|
|
bool InternallyInconsistent;
|
|
|
|
|
2003-11-09 19:39:48 +00:00
|
|
|
// LastUnique - This value is used to retain the last unique value used
|
|
|
|
// by getUniqueName to generate unique names.
|
|
|
|
unsigned long LastUnique;
|
|
|
|
|
2001-10-23 01:53:01 +00:00
|
|
|
inline super::value_type operator[](const Type *Ty) {
|
|
|
|
assert(0 && "Should not use this operator to access symbol table!");
|
|
|
|
return super::value_type();
|
|
|
|
}
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
// insertEntry - Insert a value into the symbol table with the specified
|
|
|
|
// name...
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
void insertEntry(const std::string &Name, const Type *Ty, Value *V);
|
2001-09-07 16:21:36 +00:00
|
|
|
|
2001-10-23 01:53:01 +00:00
|
|
|
// removeEntry - Remove a value from the symbol table...
|
|
|
|
//
|
|
|
|
Value *removeEntry(iterator Plane, type_iterator Entry);
|
|
|
|
|
2001-09-07 16:21:36 +00:00
|
|
|
// This function is called when one of the types in the type plane are refined
|
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|