Add support for named functions
authorChris Lattner <sabre@nondot.org>
Mon, 13 Jan 2003 01:00:48 +0000 (01:00 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 13 Jan 2003 01:00:48 +0000 (01:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5258 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/JIT/JIT.h
lib/ExecutionEngine/JIT/VM.cpp
lib/ExecutionEngine/JIT/VM.h

index d3745e508273a4197ad489c098c183cf2c9cc48b..3b267ed877bba7c4824778d53ffc3280ec541b6e 100644 (file)
@@ -44,6 +44,12 @@ public:
 
   void *resolveFunctionReference(void *RefAddr);
 
+  /// getPointerToNamedFunction - This method returns the address of the
+  /// specified function by using the dlsym function call.  As such it is only
+  /// useful for resolving library symbols, not code generated symbols.
+  ///
+  void *getPointerToNamedFunction(const std::string &Name);
+
 private:
   static MachineCodeEmitter *createEmitter(VM &V);
   void setupPassManager();
index f66d4d7b7ea267f3fd4f2a9906d13460afc89b70..c107438f0f2fd9f45f9f09efbe0190f42eb9d018 100644 (file)
@@ -55,6 +55,22 @@ const std::string &VM::getFunctionReferencedName(void *RefAddr) {
 
 static void NoopFn() {}
 
+/// getPointerToNamedFunction - This method returns the address of the specified
+/// function by using the dlsym function call.  As such it is only useful for
+/// resolving library symbols, not code generated symbols.
+///
+void *VM::getPointerToNamedFunction(const std::string &Name) {
+  // If it's an external function, look it up in the process image...
+  void *Ptr = dlsym(0, Name.c_str());
+  if (Ptr == 0) {
+    std::cerr << "WARNING: Cannot resolve fn '" << Name
+             << "' using a dummy noop function instead!\n";
+    Ptr = (void*)NoopFn;
+  }
+  
+  return Ptr;
+}
+
 /// getPointerToFunction - This method is used to get the address of the
 /// specified function, compiling it if neccesary.
 ///
@@ -62,17 +78,8 @@ void *VM::getPointerToFunction(const Function *F) {
   void *&Addr = GlobalAddress[F];   // Function already code gen'd
   if (Addr) return Addr;
 
-  if (F->isExternal()) {
-    // If it's an external function, look it up in the process image...
-    void *Ptr = dlsym(0, F->getName().c_str());
-    if (Ptr == 0) {
-      std::cerr << "WARNING: Cannot resolve fn '" << F->getName()
-                << "' using a dummy noop function instead!\n";
-      Ptr = (void*)NoopFn;
-    }
-
-    return Addr = Ptr;
-  }
+  if (F->isExternal())
+    return Addr = getPointerToNamedFunction(F->getName());
 
   // JIT all of the functions in the module.  Eventually this will JIT functions
   // on demand.  This has the effect of populating all of the non-external
index d3745e508273a4197ad489c098c183cf2c9cc48b..3b267ed877bba7c4824778d53ffc3280ec541b6e 100644 (file)
@@ -44,6 +44,12 @@ public:
 
   void *resolveFunctionReference(void *RefAddr);
 
+  /// getPointerToNamedFunction - This method returns the address of the
+  /// specified function by using the dlsym function call.  As such it is only
+  /// useful for resolving library symbols, not code generated symbols.
+  ///
+  void *getPointerToNamedFunction(const std::string &Name);
+
 private:
   static MachineCodeEmitter *createEmitter(VM &V);
   void setupPassManager();