hi, im creating a music application(image below). At the moment im using tcc compiler but im moving across to clang because of the improved compiler warnings. Can anyone please explain and show code so I can use clang's JIT to call functions in my application? Thanks. http://old.nabble.com/file/p29449300/51709341.jpeg -- View this message in context: http://old.nabble.com/clang%3A-call-extern-function-using-JIT-tp29449300p29449300.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Aug 17, 2010, at 1:56 PM, gafferuk wrote:> > hi, im creating a music application(image below). > > At the moment im using tcc compiler but im moving across to clang because of > the improved compiler warnings. > Can anyone please explain and show code so I can use clang's JIT to call > functions in my application?You'll probably want to take a look at the Kaleidoscope tutorial[1] on how to get the JIT up and running inside an application of its own. If you can give me a little more information as to what you're trying to JIT it'd be helpful. -eric [1] http://llvm.org/docs/tutorial/
Can someone pease tell me what I am doing wrong? 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(); std::string Error; llvm::OwningPtr<llvm::ExecutionEngine> EE( llvm::ExecutionEngine::createJIT(Mod, &Error)); if (!EE) { llvm::errs() << "unable to make execution engine: " << Error << "\n"; return 255; } // code I have added ------------------------------------------------------------------------------------------- -- llvm::FunctionType* ft = llvm::FunctionType::get(llvm::Type::getInt32Ty (llvm::getGlobalContext()), std::vector<const llvm::Type*>(0, llvm::Type::getInt32Ty (llvm::getGlobalContext())), false); llvm::Function* f = llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "yipee", Mod); EE->addGlobalMapping(f, yipee); llvm::Function *YipeeFn = Mod->getFunction("yipee"); if (!YipeeFn) { llvm::errs() << "'yipee' function not found in module.\n"; return 255; } // end code I have added ------------------------------------------------------------------------------------------- -- llvm::Function *EntryFn = Mod->getFunction("main"); if (!EntryFn) { llvm::errs() << "'main' function not found in module.\n"; return 255; } // FIXME: Support passing arguments. std::vector<std::string> Args; Args.push_back(Mod->getModuleIdentifier()); return EE->runFunctionAsMain(EntryFn, Args, envp); } // here the C code to be ran with JIT ------------------------------------------------------------------- int main() { int dd = yipee(1); return 1; } ----------------------------------------------------------------------------------------------- gafferuk wrote:> > hi, im creating a music application(image below). > > At the moment im using tcc compiler but im moving across to clang because > of the improved compiler warnings. > Can anyone please explain and show code so I can use clang's JIT to call > functions in my application? > > Thanks. > > http://old.nabble.com/file/p29449300/51709341.jpeg >-- View this message in context: http://old.nabble.com/clang%3A-call-extern-function-using-JIT-tp29449300p29449502.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
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.
Im trying to call fuctions in my music application from c code which will be used by the JIT. Here my function, i have made no other changes to the clang interpreter example. Can you see anything else I have to add to either the fuction below or to the c code to be JIT at the bottom? // function I wish to call. int yipee(int aVar) { aVar = 5; } int Execute(llvm::Module *Mod, char * const *envp) { llvm::InitializeNativeTarget(); std::string Error; llvm::OwningPtr<llvm::ExecutionEngine> EE( llvm::ExecutionEngine::createJIT(Mod, &Error)); if (!EE) { llvm::errs() << "unable to make execution engine: " << Error << "\n"; return 255; } // code I have added --------------------------------------------------------------------------------------------- llvm::FunctionType* ft llvm::FunctionType::get(llvm::Type::getInt32Ty(llvm::getGlobalContext()), std::vector<const llvm::Type*>(0, llvm::Type::getInt32Ty(llvm::getGlobalContext())), false); llvm::Function* f = llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "yipee", Mod); EE->addGlobalMapping(f, yipee); llvm::Function *YipeeFn = Mod->getFunction("yipee"); if (!YipeeFn) { llvm::errs() << "'yipee' function not found in module.\n"; return 255; } // end code I have added --------------------------------------------------------------------------------------------- llvm::Function *EntryFn = Mod->getFunction("main"); if (!EntryFn) { llvm::errs() << "'main' function not found in module.\n"; return 255; } // FIXME: Support passing arguments. std::vector<std::string> Args; Args.push_back(Mod->getModuleIdentifier()); return EE->runFunctionAsMain(EntryFn, Args, envp); } // here the C code to be ran with JIT ------------------------------------------------------------------- int main() { int dd = yipee(1); return 1; } Heres another screenshot of my music application, im very happy with the results but the code editor is lookin a little bare, i really need clang! :) http://old.nabble.com/file/p29469972/87647073.jpeg Eric Christopher-2 wrote:> > > On Aug 17, 2010, at 1:56 PM, gafferuk wrote: > >> >> hi, im creating a music application(image below). >> >> At the moment im using tcc compiler but im moving across to clang because >> of >> the improved compiler warnings. >> Can anyone please explain and show code so I can use clang's JIT to call >> functions in my application? > > You'll probably want to take a look at the Kaleidoscope tutorial[1] on how > to get > the JIT up and running inside an application of its own. If you can give > me > a little more information as to what you're trying to JIT it'd be helpful. > > -eric > > [1] http://llvm.org/docs/tutorial/ > _______________________________________________ > 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-tp29449300p29469972.html Sent from the LLVM - Dev mailing list archive at Nabble.com.