Add Module::getTypeName
authorChris Lattner <sabre@nondot.org>
Sat, 13 Apr 2002 18:58:33 +0000 (18:58 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 13 Apr 2002 18:58:33 +0000 (18:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2237 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d94500aed45ee121a993deeaa774275b17943b57..cd151786b6c0887a3dd248afdd82e9b887fb59d4 100644 (file)
@@ -69,6 +69,11 @@ public:
   //
   bool addTypeName(const std::string &Name, const Type *Ty);
 
+  // getTypeName - If there is at least one entry in the symbol table for the
+  // specified type, return it.
+  //
+  std::string getTypeName(const Type *Ty);
+
   // Get the underlying elements of the Module...
   inline const GlobalListType &getGlobalList() const  { return GlobalList; }
   inline       GlobalListType &getGlobalList()        { return GlobalList; }
index 74b5f4b7fdc28440c0c6a2fa7eea0a06ee3f5d02..f3d7cd976f3b68024191ba68e6333714fec54e81 100644 (file)
@@ -86,6 +86,26 @@ bool Module::addTypeName(const std::string &Name, const Type *Ty) {
   return false;
 }
 
+// getTypeName - If there is at least one entry in the symbol table for the
+// specified type, return it.
+//
+std::string Module::getTypeName(const Type *Ty) {
+  const SymbolTable *ST = getSymbolTable();
+  if (ST == 0) return "";  // No symbol table, must not have an entry...
+  if (ST->find(Type::TypeTy) == ST->end())
+    return ""; // No names for types...
+
+  SymbolTable::type_const_iterator TI = ST->type_begin(Type::TypeTy);
+  SymbolTable::type_const_iterator TE = ST->type_end(Type::TypeTy);
+
+  while (TI != TE && TI->second != (const Value*)Ty)
+    ++TI;
+
+  if (TI != TE)  // Must have found an entry!
+    return TI->first;
+  return "";     // Must not have found anything...
+}
+
 
 // dropAllReferences() - This function causes all the subinstructions to "let
 // go" of all references that they are maintaining.  This allows one to