aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Module.h6
-rw-r--r--lib/VMCore/Module.cpp15
2 files changed, 18 insertions, 3 deletions
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index 6f7a14f..4d2edce 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -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.
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index fec6fec..c12b32d 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -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...
}