
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 0.72 KB | hits: 13 | expires: Never
Calling LLVM bitcode function in LLVM 2.8
void hello() {}
llvm-gcc -c -emit-llvm hello.c -o hello.bc
using namespace std;
using namespace llvm;
void callFunction(string file, string function) {
InitializeNativeTarget();
LLVMContext context;
string error;
MemoryBuffer* buff = MemoryBuffer::getFile(file);
Module* m = getLazyBitcodeModule(buff, context, &error);
// Check the module parsed here.
// ...
ExecutionEngine* engine = ExecutionEngine::create(m);
// Check the engine started up correctly here.
// ...
Function* func = m->getFunction(function);
// Check the function was found here.
// ..
vector<GenericValue> args(0);
// This is what crashes.
engine->runFunction(func, args);
}