[LLVMdev] clang: call extern function using JIT

gafferuk gafferuk at gmail.com
Wed Aug 18 04:12:46 PDT 2010


ok, i have changed functionType code to:

	llvm::FunctionType* ft =
llvm::FunctionType::get(llvm::Type::getInt32Ty(llvm::getGlobalContext()),
		std::vector<const llvm::Type*>(1,
llvm::Type::getInt32Ty(llvm::getGlobalContext())), false);

when I run my app the compiler says:
E:\Projects\Whistle\Whistle\Release>Whistle file.c
file.c(3) :  warning: implicit declaration of function 'yipee' is invalid in
C99

      [-Wimplicit-function-declaration]
    int dd = yipee(1);
             ^
1 warning generated.
LLVM ERROR: Program used external function 'yipee' which could not be
resolved!
Stack dump:
0.      Running pass 'X86 Machine Code Emitter' on function '@main'



and if I change the code to be ran on the JIT to this:

extern int yipee;
int main()
{
    int dd = yipee(1);

    return 0;
}

I get this error:

E:\Projects\Whistle\Whistle\Release>Whistle file.c
file.c(5) :  error: called object type 'int' is not a function or function
      pointer
    int dd = yipee(1);
             ~~~~~^
1 error generated.











Óscar Fuentes wrote:
> 
> gafferuk <gafferuk at gmail.com> writes:
> 
>> Can someone pease tell me what I am doing wrong?
> 
> It is hard to say because you don't say what the problem is, but let's
> try.
> 
>> Im trying to register an external function with the JIT, so can call
>> functions in my music 
>>
>> application.
>>
>> Here my function
>>
>> int Execute(llvm::Module *Mod, char * const *envp) {
>> 	llvm::InitializeNativeTarget();
> 
> It is not necessary to call InitializeNativeTarget each time. One is
> enough.
> 
> [snip]
> 
>> 	llvm::FunctionType* ft = llvm::FunctionType::get(llvm::Type::getInt32Ty
>>
>> (llvm::getGlobalContext()),
>> 		std::vector<const llvm::Type*>(0, llvm::Type::getInt32Ty
> _______________________________________________^
> 
> You are creating a vector of Type's with *zero* elements, so the effect
> of this is a FuntionType that takes zero arguments.
> 
> [snip]
> 
> Next time please be more explicit on the descripcion of the problem.
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 

-- 
View this message in context: http://old.nabble.com/clang%3A-call-extern-function-using-JIT-tp29449300p29470076.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.





More information about the llvm-dev mailing list