[llvm-commits] CVS: llvm/tools/lli/JIT/VM.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Jan 12 19:01:13 PST 2003


Changes in directory llvm/tools/lli/JIT:

VM.cpp updated: 1.1 -> 1.2

---
Log message:

Add support for named functions


---
Diffs of the changes:

Index: llvm/tools/lli/JIT/VM.cpp
diff -u llvm/tools/lli/JIT/VM.cpp:1.1 llvm/tools/lli/JIT/VM.cpp:1.2
--- llvm/tools/lli/JIT/VM.cpp:1.1	Mon Dec 23 18:01:05 2002
+++ llvm/tools/lli/JIT/VM.cpp	Sun Jan 12 19:00:38 2003
@@ -55,6 +55,22 @@
 
 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 *&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





More information about the llvm-commits mailing list