Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Calling LLVM bitcode function in LLVM 2.8
  2. void hello() {}
  3.        
  4. llvm-gcc -c -emit-llvm hello.c -o hello.bc
  5.        
  6. using namespace std;
  7. using namespace llvm;
  8.  
  9. void callFunction(string file, string function) {
  10.   InitializeNativeTarget();
  11.  
  12.   LLVMContext context;
  13.   string error;
  14.  
  15.   MemoryBuffer* buff = MemoryBuffer::getFile(file);
  16.   Module* m = getLazyBitcodeModule(buff, context, &error);
  17.  
  18.   // Check the module parsed here.
  19.   // ...
  20.  
  21.   ExecutionEngine* engine = ExecutionEngine::create(m);
  22.  
  23.   // Check the engine started up correctly here.
  24.   // ...
  25.  
  26.   Function* func = m->getFunction(function);
  27.  
  28.   // Check the function was found here.
  29.   // ..
  30.  
  31.   vector<GenericValue> args(0);
  32.  
  33.   // This is what crashes.
  34.   engine->runFunction(func, args);
  35. }