llvm - How to call a pointer that points to a C function -
i have pointer function need invoke without going through llvm::module::getorinsertfunction. illustration not work:
static int add(int x, int y); llvm::value *one, *two; llvm::constant* addfn = llvm::constantint::get(jb->getintptrty(datalayout), (intptr_t)add); llvm::type* args[] = { int32ty, int32ty }; llvm::functiontype* ftype = llvm::functiontype::get(int32ty, args); addfn = llvm::constantexpr::getpointercast(addfn, ftype); createcall(addfn, one, two);
is there way? or must phone call getorinsertfunction?
looks works:
static int add(int x, int y) { homecoming x + y; } llvm::constant* addfn = llvm::constantint::get(builder->getintptrty(datalayout), (intptr_t)add); llvm::functiontype* ftype = 0; { llvm::type* args[] = { int32ty, int32ty }; ftype = ftype->get(int32ty, args); } llvm::constant* pp = llvm::constantexpr::getinttoptr(addfn, llvm::pointertype::getunqual(ftype)); addfn = llvm::constantexpr::getpointercast(pp, ftype->getpointerto()); jit_value_t sum = jb->createcall2(addfn, value1, value2);
llvm llvm-c++-api
No comments:
Post a Comment