Renato Golin
2009-Aug-22 21:13 UTC
[LLVMdev] Having JIT resolve extern "C" functions declared in executible
2009/7/4 Albert Graef <Dr.Graef at t-online.de>:> This is all I ever needed to interface to C functions using LLVM. It's > really easy. Of course you still need a prototype of the external > function (function definition without body) in your IR, but that's it.Hi Albert, I'm having a similar problem and I found I can't declare the function and use it, most likely because my syntax is wrong. I have the function extern'd and am creating only the signature on the IR code (attached). The idea is that it creates something like this: My variable is DoubleTy and the expected parameter is also, but I'm getting this error: Assertion `(0 == FTy->getNumParams() || FTy->getParamType(0) =Actual->getType()) && "Calling a function with a bad signature!"' cheers, --renato Reclaim your digital rights, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm -------------- next part -------------- A non-text attachment was scrubbed... Name: extern.cpp Type: text/x-c++src Size: 1621 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090822/16d57f2b/attachment.cpp>
Renato Golin
2009-Aug-23 09:35 UTC
[LLVMdev] Having JIT resolve extern "C" functions declared in executible
2009/8/22 Bill Wendling <isanbard at gmail.com>:> I think you might have to provide an empty list if your function doesn't > take parameters. Maybe using an irbuilder would help?It does take one parameter. Here's the important bits: // My Function extern "C" void print(double X) { printf("%f\n", X); } // Args type std::vector<const Type*> args(1, Type::getDoubleTy(getGlobalContext())); // return void, 1 arg double, no varargs FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), args, false); // creating stub for print function Function* printFunction = Function::Create(FT, Function::ExternalLinkage, "print", module); By doing this (and the variable declaration below), my IR is: ; ModuleID = 'example' define void @main() { entry: %var = alloca double ; <double*> [#uses=1] store double 1.000000e+01, double* %var } declare void @print(double) ; ================== END The function call is, then: // Number 10 Value* value = ConstantFP::get(getGlobalContext(), APFloat(10.0)); // Variable var is double Value* var = builder.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, "var"); // Assign it value 10 builder.CreateStore(value, var); // Create a call to the function, passing a double var builder.CreateCall(printFunction, var, "print"); If var is DoubleTy and the arg is expecting DoubleTy, why is the assert failing? I've tried creating a vector with the var inside and create the function as below, but got the same error: builder.CreateCall(printFunction, vec.begin(), vec.end(), "print"); cheers, --renato Reclaim your digital rights, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm
Maybe Matching Threads
- [LLVMdev] Having JIT resolve extern "C" functions declared in executible
- [LLVMdev] Having JIT resolve extern "C" functions declared in executible
- [LLVMdev] noob IR builder question
- [LLVMdev] Problem about the type of Function's arguement in llvm
- [LLVMdev] Getting Kaleidoscope to compile