Factor parentness out of Module & GlobalVariable into GlobalValue
authorChris Lattner <sabre@nondot.org>
Wed, 3 Oct 2001 19:28:15 +0000 (19:28 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 3 Oct 2001 19:28:15 +0000 (19:28 +0000)
Implement SymbolTable debug/dump utility

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@710 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ConstPoolVals.h
include/llvm/Function.h
include/llvm/GlobalValue.h
include/llvm/GlobalVariable.h
include/llvm/SymbolTable.h
lib/VMCore/ConstPoolVals.cpp
lib/VMCore/Function.cpp
lib/VMCore/SymbolTable.cpp

index 235ab12f26361b0f0db3d50e7545fa94fd329aac..3fe8e099cf4f0f15988a5d2ad6440d726473a4ba 100644 (file)
@@ -232,10 +232,7 @@ protected:
   ConstPoolPointerReference(GlobalValue *GV);
   ~ConstPoolPointerReference() {}
 public:
-  static ConstPoolPointerReference *get(GlobalValue *GV) {
-    // FIXME: These should all be shared!
-    return new ConstPoolPointerReference(GV);
-  }
+  static ConstPoolPointerReference *get(GlobalValue *GV);
 
   virtual string getStrValue() const;
 
index d7c35b3c040b625f2b4fc9f95b9a42cd5ea54865..fe878bf45e88a9dbbd39a8a1b448943c0c2217ea 100644 (file)
@@ -38,8 +38,6 @@ private:
   BasicBlocksType  BasicBlocks;    // The basic blocks
   ArgumentListType ArgumentList;   // The formal arguments
 
-  Module *Parent;                  // The module that contains this method
-
   friend class ValueHolder<Method, Module, Module>;
   void setParent(Module *parent);
 
@@ -58,10 +56,6 @@ public:
   bool isExternal() const { return BasicBlocks.empty(); }
 
 
-  // Get the class structure that this method is contained inside of...
-  inline Module *getParent() { return Parent; }
-  inline const Module *getParent() const { return Parent; }
-
   // Get the underlying elements of the Method...
   inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
   inline       ArgumentListType &getArgumentList()      { return ArgumentList; }
index 394e2a262a1e68f0c22136774ffd3960632ea617..baee0bf4e085c5a99e6c9c8842ae0420fc19bd18 100644 (file)
@@ -17,14 +17,21 @@ class GlobalValue : public User {
   GlobalValue(const GlobalValue &);             // do not implement
 protected:
   GlobalValue(const Type *Ty, ValueTy vty, const string &name = "")
-    : User(Ty, vty, name) {}
+    : User(Ty, vty, name) { Parent = 0; }
+
+  Module *Parent;
 public:
+  ~GlobalValue() {}
 
-  // getType - Global values are always pointers (FIXME, methods should be ptrs too!)
+  // getType - Global values are always pointers.
   inline const PointerType *getType() const {
     return (const PointerType*)User::getType();
   }
 
+  // Get the module that this global value is contained inside of...
+  inline Module *getParent() { return Parent; }
+  inline const Module *getParent() const { return Parent; }
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GlobalValue *T) { return true; }
   static inline bool classof(const Value *V) {
index 6d6de1414665767e49af7ff1ca4f7ac2a039ba64..2e298058f5245a086036588eb72159a98e8c1556 100644 (file)
@@ -19,8 +19,6 @@ class ConstPoolVal;
 class PointerType;
 
 class GlobalVariable : public GlobalValue {
-  Module *Parent;                  // The module that contains this method
-
   friend class ValueHolder<GlobalVariable, Module, Module>;
   void setParent(Module *parent) { Parent = parent; }
 
@@ -33,9 +31,6 @@ public:
   // Specialize setName to handle symbol table majik...
   virtual void setName(const string &name, SymbolTable *ST = 0);
 
-  inline       Module *getParent()       { return Parent; }
-  inline const Module *getParent() const { return Parent; }
-
   // The initializer for the global variable/constant is held by Operands[0] if
   // an initializer is specified.
   //
index bae9eb148122f345e5ccc23d567b55a0669476a8..69ff3ddad57f98f924b4b0ad3f1257406a879747 100644 (file)
@@ -103,6 +103,8 @@ public:
     return find(TypeID)->second.end(); 
   }
 
+  void dump() const;  // Debug method, print out symbol table
+
 private:
   // insertEntry - Insert a value into the symbol table with the specified
   // name...
index eeb7a43069fa0c6d95951650494f5e993fded04d..be1e582d157335b5cce66fcc4d924dec4cf46667 100644 (file)
@@ -343,3 +343,10 @@ ConstPoolPointer *ConstPoolPointer::getNull(const PointerType *Ty) {
   return Result;
 }
 
+//---- ConstPoolPointerReference::get() implementation...
+//
+ConstPoolPointerReference *ConstPoolPointerReference::get(GlobalValue *GV) {
+  assert(GV->getParent());
+  // FIXME: These should all be shared!
+  return new ConstPoolPointerReference(GV);
+}
index 372d0d28b91161a8781a99db51e7ed42f09ba170..6e30fe80a776f8dd785956d8637963335519b6d4 100644 (file)
@@ -29,7 +29,6 @@ Method::Method(const MethodType *Ty, const string &name)
   : GlobalValue(PointerType::get(Ty), Value::MethodVal, name),
     SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
   assert(::isa<MethodType>(Ty) && "Method signature must be of method type!");
-  Parent = 0;
 }
 
 Method::~Method() {
@@ -90,7 +89,7 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool isConstant,
                               ConstPoolVal *Initializer = 0, 
                               const string &Name = "")
   : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, Name),
-    Parent(0), Constant(isConstant) {
+    Constant(isConstant) {
   if (Initializer) Operands.push_back(Use((Value*)Initializer, this));
 
   assert(!isConstant || hasInitializer() &&
index 12bf0c7f1baa3fe14f76dfde3959ef39097253fc..09465305e65e26bd47021d07ba8f66940fc5fd04 100644 (file)
@@ -173,3 +173,29 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
        cast<const DerivedType>(NewType)->addAbstractTypeUser(this);
     }
 }
+
+
+#ifndef NDEBUG
+#include "llvm/Assembly/Writer.h"
+#include <algorithm>
+
+static void DumpVal(const pair<const string, Value *> &V) {
+  cout << "  '%" << V.first << "' = " << V.second << endl;
+}
+
+static void DumpPlane(const pair<const Type *, map<const string, Value *> >&P) {
+  cout << "  Plane: " << P.first << endl;
+  for_each(P.second.begin(), P.second.end(), DumpVal);
+}
+
+void SymbolTable::dump() const {
+  cout << "Symbol table dump:\n";
+  for_each(begin(), end(), DumpPlane);
+
+  if (ParentSymTab) {
+    cout << "Parent ";
+    ParentSymTab->dump();
+  }
+}
+
+#endif