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

Chris Lattner lattner at cs.uiuc.edu
Wed Dec 4 00:05:01 PST 2002


Changes in directory llvm/tools/jello:

VM.cpp updated: 1.2 -> 1.3

---
Log message:

Implement external function support


---
Diffs of the changes:

Index: llvm/tools/jello/VM.cpp
diff -u llvm/tools/jello/VM.cpp:1.2 llvm/tools/jello/VM.cpp:1.3
--- llvm/tools/jello/VM.cpp:1.2	Tue Dec  3 22:47:34 2002
+++ llvm/tools/jello/VM.cpp	Wed Dec  4 00:04:07 2002
@@ -10,6 +10,7 @@
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/Function.h"
 #include <iostream>
+#include <dlfcn.h>    // dlsym access
 
 
 VM::~VM() {
@@ -58,6 +59,7 @@
   return FunctionRefs[RefAddr]->getName();
 }
 
+static void NoopFn() {}
 
 /// getPointerToFunction - This method is used to get the address of the
 /// specified function, compiling it if neccesary.
@@ -67,7 +69,15 @@
   if (Addr) return Addr;
 
   if (F->isExternal()) {
-    assert(0 && "VM::getPointerToFunction: Doesn't handle external fn's yet!");
+    // 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;
   }
 
   // JIT all of the functions in the module.  Eventually this will JIT functions





More information about the llvm-commits mailing list