Add new addTypeName method to Module class
authorChris Lattner <sabre@nondot.org>
Fri, 29 Mar 2002 04:48:40 +0000 (04:48 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 29 Mar 2002 04:48:40 +0000 (04:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2037 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/VMCore/Module.cpp

index a2a8e507285ee15f41c7e7c804b3fac97908e882..bc7f564a8fd29e7eadfc5c1efba9fe551c382452 100644 (file)
@@ -63,6 +63,12 @@ public:
   //
   Function *getFunction(const std::string &Name, const FunctionType *Ty);
 
+  // addTypeName - Insert an entry in the symbol table mapping Str to Type.  If
+  // there is already an entry for this name, true is returned and the symbol
+  // table is not modified.
+  //
+  bool addTypeName(const std::string &Name, const Type *Ty);
+
   // Get the underlying elements of the Module...
   inline const GlobalListType &getGlobalList() const  { return GlobalList; }
   inline       GlobalListType &getGlobalList()        { return GlobalList; }
index c0767cd7d194353b57b74c4e5efbc097cf6e5a82..9d131699700cdac9edcfa24e6745e9be5f7ccc61 100644 (file)
@@ -70,6 +70,21 @@ Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
   return cast_or_null<Function>(SymTab->lookup(PointerType::get(Ty), Name));
 }
 
+// addTypeName - Insert an entry in the symbol table mapping Str to Type.  If
+// there is already an entry for this name, true is returned and the symbol
+// table is not modified.
+//
+bool Module::addTypeName(const std::string &Name, const Type *Ty) {
+  SymbolTable *ST = getSymbolTableSure();
+
+  if (ST->lookup(Type::TypeTy, Name)) return true;  // Already in symtab...
+  
+  // Not in symbol table?  Set the name with the Symtab as an argument so the
+  // type knows what to update...
+  ((Value*)Ty)->setName(Name, ST);
+
+  return false;
+}
 
 
 // dropAllReferences() - This function causes all the subinstructions to "let