Add a new Module::getNamedFunction method
authorChris Lattner <sabre@nondot.org>
Tue, 19 Nov 2002 18:41:44 +0000 (18:41 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Nov 2002 18:41:44 +0000 (18:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4758 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6f7a14f410be25ba40cb7f12c7776fc8f198e3ea..4d2edceb73d193535c0c28515f87d04f73f705ee 100644 (file)
@@ -86,6 +86,12 @@ public:
   ///
   Function *getMainFunction();
 
+  /// getNamedFunction - Return the first function in the module with the
+  /// specified name, of arbitrary type.  This method returns null if a function
+  /// with the specified name is not found.
+  ///
+  Function *getNamedFunction(const std::string &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.
index fec6fec77d376428d6c23d10b85675bb8b3d2af9..c12b32d7c1395b6e1aae88970e0df52b0f360137 100644 (file)
@@ -182,11 +182,20 @@ Function *Module::getMainFunction() {
       return F;
   }
 
-  // Loop over all of the methods, trying to find main the hard way...
+  // Ok, try to find main the hard way...
+  return getNamedFunction("main");
+}
+
+/// getNamedFunction - Return the first function in the module with the
+/// specified name, of arbitrary type.  This method returns null if a function
+/// with the specified name is not found.
+///
+Function *Module::getNamedFunction(const std::string &Name) {
+  // Loop over all of the functions, looking for the function desired
   for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->getName() == "main")
+    if (I->getName() == Name)
       return I;
-  return 0; // Main not found...
+  return 0; // function not found...
 }