开发者

Calling LLVM bitcode function in LLVM 2.8

I'm trying to read and call a function parsed from LLVM bitco开发者_开发知识库de in LLVM 2.8. I have everything working apart from the actual call, which crashes the program.

First I have this C code:

void hello() {}

I've compiled this with:

llvm-gcc -c -emit-llvm hello.c -o hello.bc

Here's a trimmed down version of the code that's supposed to read it:

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);
}

I've included plenty of LLVM headers, including ExecutionEngine/JIT.h, and the code checks at each step to make sure values aren't NULL. It parses the bitcode, and I have examined the function it finds to confirm it was as expected.

I've also tried building a module and function myself, which works as expected, so the problem definitely arises from the fact that the function is produced by the bitcode.


I've managed to get this running as expected. I was curious if the problem lay in the above process, but this is obviously not the case. The system I was running this as a part of was causing the crash, and the code above does work on its own.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜