Hi Gordon, I wrote a small example, but while running I get an error("Tied to execute an unknown external function"), where I am wrong? Thanks in advance. Kirill. int some_test_func( int ){ std::cout << "!!!!" << std::endl; return 8848; } int _tmain(int argc, _TCHAR* argv[]){ Module *M = new Module("test"); ExistingModuleProvider* MP = new ExistingModuleProvider(M); ExecutionEngine* EE = ExecutionEngine::create(MP, false); std::vector<const Type *> func_args; func_args.push_back(Type::Int32Ty); FunctionType * func_type = FunctionType::get(Type::Int32Ty, func_args, false); Function * my_function = Function::Create( func_type, Function::ExternalLinkage, "some_test_func", M ); EE->addGlobalMapping( my_function, (void*)&some_test_func ); Function *FooF = cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); Value *Ten = ConstantInt::get(Type::Int32Ty, 10); CallInst *Add1CallRes = CallInst::Create(my_function, Ten, "some_test_func", BB); Add1CallRes->setTailCall(true); ReturnInst::Create(Add1CallRes, BB); std::cout << "We just constructed this LLVM module:\n\n" << *M; std::cout << "\n\nRunning foo: " << std::flush; std::vector<GenericValue> noargs; GenericValue gv = EE->runFunction(FooF, noargs); std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; return 0; } 2008/8/19, Gordon Henriksen <gordonhenriksen at me.com>:> > On Aug 19, 2008, at 13:36, kirill havok wrote: > > I got very interested in LLVM project, and I decided to start writing my own > scripting language based on it. By studying the documentation, I could not > find how to call external function, written in C. That is, I have a set of > functions written in C/C++, I generate code, using LLVM C++ interface, how > can I call(or register in machine in run-time) my external functions? Maybe > I just missed something. Please, give in which direction to search. > > Hi Kirill, > > Since LLVM goes to the bare metal, there is no need for an "FFI" or bindings > to call native code. Simply create a declaration for the function—a Function > with no body—and call it as any other function in your program. (Also, of > course, link with a library to define the symbols.) It might be instructive > to examine the llvm-gcc -S -emit-llvm output of a program like this: > > int MyExternalFn(int, int, int); > > int main(int, const char**, const char**) { > return MyExternalFn(1, 2, 3); > } > > > Where you tweak MyExternalFn to have the desired prototype. > > To create a function declaration: > > > From C++, simply call Function::Create and then do not add any basic blocks. > From LLVM assembly, use the keyword "declare" instead of "define": > http://llvm.org/docs/LangRef.html#functionstructure > > > If you're using the JIT, you'll need to do the above, but also may need to > register your functions using > ExecutionEngine::addGlobalMapping. > > http://llvm.org/doxygen/classllvm_1_1ExecutionEngine.html#a8 > > > Note that the C calling convention do not map directly to LLVM IR for many > cases, so it's best to stick to simple parameter types (pointers and ints, > for example) and also to verify that the LLVM FunctionTypes you use are > correct on each platform you support. > > Good luck! > > — Gordon > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
kirill havok wrote:> Hi Gordon, > I wrote a small example, but while running I get an error("Tied to > execute an unknown external function"), where I am wrong? >I think the problem is that some_test_func() is a C++ function, so its name is being mangled during compilation. To fix it, I think you want to add a declaration telling the compiler to treat some_test_func() as a C function. Something like the below will work: extern "C" { int some_test_func(int); } int some_test_func (int) { <code for function here> ... } -- John T.> Thanks in advance. > Kirill. > > int some_test_func( int ){ > std::cout << "!!!!" << std::endl; > return 8848; > } > > int _tmain(int argc, _TCHAR* argv[]){ > > Module *M = new Module("test"); > ExistingModuleProvider* MP = new ExistingModuleProvider(M); > ExecutionEngine* EE = ExecutionEngine::create(MP, false); > > std::vector<const Type *> func_args; > func_args.push_back(Type::Int32Ty); > FunctionType * func_type = FunctionType::get(Type::Int32Ty, func_args, false); > Function * my_function = Function::Create( func_type, > Function::ExternalLinkage, "some_test_func", M ); > EE->addGlobalMapping( my_function, (void*)&some_test_func ); > > Function *FooF = cast<Function>(M->getOrInsertFunction("foo", > Type::Int32Ty, (Type *)0)); > BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); > Value *Ten = ConstantInt::get(Type::Int32Ty, 10); > CallInst *Add1CallRes = CallInst::Create(my_function, Ten, > "some_test_func", BB); > Add1CallRes->setTailCall(true); > > ReturnInst::Create(Add1CallRes, BB); > > std::cout << "We just constructed this LLVM module:\n\n" << *M; > std::cout << "\n\nRunning foo: " << std::flush; > > std::vector<GenericValue> noargs; > GenericValue gv = EE->runFunction(FooF, noargs); > > std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; > return 0; > } > > > > 2008/8/19, Gordon Henriksen <gordonhenriksen at me.com>: > >> On Aug 19, 2008, at 13:36, kirill havok wrote: >> >> I got very interested in LLVM project, and I decided to start writing my own >> scripting language based on it. By studying the documentation, I could not >> find how to call external function, written in C. That is, I have a set of >> functions written in C/C++, I generate code, using LLVM C++ interface, how >> can I call(or register in machine in run-time) my external functions? Maybe >> I just missed something. Please, give in which direction to search. >> >> Hi Kirill, >> >> Since LLVM goes to the bare metal, there is no need for an "FFI" or bindings >> to call native code. Simply create a declaration for the function—a Function >> with no body—and call it as any other function in your program. (Also, of >> course, link with a library to define the symbols.) It might be instructive >> to examine the llvm-gcc -S -emit-llvm output of a program like this: >> >> int MyExternalFn(int, int, int); >> >> int main(int, const char**, const char**) { >> return MyExternalFn(1, 2, 3); >> } >> >> >> Where you tweak MyExternalFn to have the desired prototype. >> >> To create a function declaration: >> >> >> From C++, simply call Function::Create and then do not add any basic blocks. >> From LLVM assembly, use the keyword "declare" instead of "define": >> http://llvm.org/docs/LangRef.html#functionstructure >> >> >> If you're using the JIT, you'll need to do the above, but also may need to >> register your functions using >> ExecutionEngine::addGlobalMapping. >> >> http://llvm.org/doxygen/classllvm_1_1ExecutionEngine.html#a8 >> >> >> Note that the C calling convention do not map directly to LLVM IR for many >> cases, so it's best to stick to simple parameter types (pointers and ints, >> for example) and also to verify that the LLVM FunctionTypes you use are >> correct on each platform you support. >> >> Good luck! >> >> — Gordon >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Hi John, Unfortunately this did not help :-( 2008/8/19, John Criswell <criswell at cs.uiuc.edu>:> kirill havok wrote: > > Hi Gordon, > > I wrote a small example, but while running I get an error("Tied to > > execute an unknown external function"), where I am wrong? > > > > I think the problem is that some_test_func() is a C++ function, so its > name is being mangled during compilation. > > To fix it, I think you want to add a declaration telling the compiler to > treat some_test_func() as a C function. Something like the below will work: > > extern "C" { > int some_test_func(int); > > } > > int some_test_func (int) { > > <code for function here> > ... > } > > -- John T. > > > > Thanks in advance. > > Kirill. > > > > int some_test_func( int ){ > > std::cout << "!!!!" << std::endl; > > return 8848; > > } > > > > int _tmain(int argc, _TCHAR* argv[]){ > > > > Module *M = new Module("test"); > > ExistingModuleProvider* MP = new ExistingModuleProvider(M); > > ExecutionEngine* EE = ExecutionEngine::create(MP, false); > > > > std::vector<const Type *> func_args; > > func_args.push_back(Type::Int32Ty); > > FunctionType * func_type = FunctionType::get(Type::Int32Ty, func_args, false); > > Function * my_function = Function::Create( func_type, > > Function::ExternalLinkage, "some_test_func", M ); > > EE->addGlobalMapping( my_function, (void*)&some_test_func ); > > > > Function *FooF = cast<Function>(M->getOrInsertFunction("foo", > > Type::Int32Ty, (Type *)0)); > > BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); > > Value *Ten = ConstantInt::get(Type::Int32Ty, 10); > > CallInst *Add1CallRes = CallInst::Create(my_function, Ten, > > "some_test_func", BB); > > Add1CallRes->setTailCall(true); > > > > ReturnInst::Create(Add1CallRes, BB); > > > > std::cout << "We just constructed this LLVM module:\n\n" << *M; > > std::cout << "\n\nRunning foo: " << std::flush; > > > > std::vector<GenericValue> noargs; > > GenericValue gv = EE->runFunction(FooF, noargs); > > > > std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; > > return 0; > > } > > > > > > > > 2008/8/19, Gordon Henriksen <gordonhenriksen at me.com>: > > > >> On Aug 19, 2008, at 13:36, kirill havok wrote: > >> > >> I got very interested in LLVM project, and I decided to start writing my own > >> scripting language based on it. By studying the documentation, I could not > >> find how to call external function, written in C. That is, I have a set of > >> functions written in C/C++, I generate code, using LLVM C++ interface, how > >> can I call(or register in machine in run-time) my external functions? Maybe > >> I just missed something. Please, give in which direction to search. > >> > >> Hi Kirill, > >> > >> Since LLVM goes to the bare metal, there is no need for an "FFI" or bindings > >> to call native code. Simply create a declaration for the function—a Function > >> with no body—and call it as any other function in your program. (Also, of > >> course, link with a library to define the symbols.) It might be instructive > >> to examine the llvm-gcc -S -emit-llvm output of a program like this: > >> > >> int MyExternalFn(int, int, int); > >> > >> int main(int, const char**, const char**) { > >> return MyExternalFn(1, 2, 3); > >> } > >> > >> > >> Where you tweak MyExternalFn to have the desired prototype. > >> > >> To create a function declaration: > >> > >> > >> From C++, simply call Function::Create and then do not add any basic blocks. > >> From LLVM assembly, use the keyword "declare" instead of "define": > >> http://llvm.org/docs/LangRef.html#functionstructure > >> > >> > >> If you're using the JIT, you'll need to do the above, but also may need to > >> register your functions using > >> ExecutionEngine::addGlobalMapping. > >> > >> http://llvm.org/doxygen/classllvm_1_1ExecutionEngine.html#a8 > >> > >> > >> Note that the C calling convention do not map directly to LLVM IR for many > >> cases, so it's best to stick to simple parameter types (pointers and ints, > >> for example) and also to verify that the LLVM FunctionTypes you use are > >> correct on each platform you support. > >> > >> Good luck! > >> > >> — Gordon > >> > >> > >> _______________________________________________ > >> LLVM Developers mailing list > >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >> > >> > >> > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Aug 19, 2008, at 16:39, John Criswell wrote:> kirill havok wrote: > >> I wrote a small example, but while running I get an error("Tied to >> execute an unknown external function"), where I am wrong? >> > > I think the problem is that some_test_func() is a C++ function, so > its name is being mangled during compilation. > > To fix it, I think you want to add a declaration telling the > compiler to treat some_test_func() as a C function. Something like > the below will work: > > extern "C" { > int some_test_func(int); > } > > int some_test_func (int) { > <code for function here> > ... > }John, that wouldn't much matter since he's registering the function by hand using addGlobalMapping. It could influence the calling convention, but the linkage is rendered irrelevant. Kirill, your test program looks nearly correct to me. Try stepping through runFunction to see what's gone awry.>> int some_test_func( int ){ >> std::cout << "!!!!" << std::endl; >> return 8848; >> } >> >> int _tmain(int argc, _TCHAR* argv[]){ >> >> Module *M = new Module("test"); >> ExistingModuleProvider* MP = new ExistingModuleProvider(M); >> ExecutionEngine* EE = ExecutionEngine::create(MP, false); >> >> std::vector<const Type *> func_args; >> func_args.push_back(Type::Int32Ty); >> FunctionType * func_type = FunctionType::get(Type::Int32Ty, >> func_args, false); >> Function * my_function = Function::Create( func_type, >> Function::ExternalLinkage, "some_test_func", M ); >> EE->addGlobalMapping( my_function, (void*)&some_test_func ); >> >> Function *FooF = cast<Function>(M->getOrInsertFunction("foo", >> Type::Int32Ty, (Type *)0)); >> BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); >> Value *Ten = ConstantInt::get(Type::Int32Ty, 10); >> CallInst *Add1CallRes = CallInst::Create(my_function, Ten, >> "some_test_func", BB); >> Add1CallRes->setTailCall(true); >> >> ReturnInst::Create(Add1CallRes, BB); >> >> std::cout << "We just constructed this LLVM module:\n\n" << >> *M; >> std::cout << "\n\nRunning foo: " << std::flush; >> >> std::vector<GenericValue> noargs; >> GenericValue gv = EE->runFunction(FooF, noargs); >> >> std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << >> "\n"; >> return 0; >> }
"kirill havok" <666khronos at gmail.com> writes:> Hi Gordon, > I wrote a small example, but while running I get an error("Tied to > execute an unknown external function"), where I am wrong?[snip] This is the sort of code I have on my JIT LLVM generator: Function *my_function = cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); EE->addGlobalMapping( my_function, (void*)&some_test_func ); It seems to me that Function::Create is not what you need :-) -- Oscar
Hello,> Unfortunately this did not help :-(Maybe you're using interpreter, not JIT? How you're linking? Also, you don't need C linkage for external stuff, since: - You're using vcpp and there is no dynamic linking on windows - You're calling EE->addGlobalMapping() explicitely -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University.
Hi Kirill, Don't forget to add X86TargetMachine.obj (add to Additional Dependencies in Linker options, if you are using MSVS) otherwise LLVM will try and use Interpreter instead of JIT. Hope this helps, Rob.> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of kirill havok > Sent: Wednesday, August 20, 2008 8:32 AM > To: LLVM Developers Mailing List > Subject: Re: [LLVMdev] Please help with LLVM C++ integration > > Hi Gordon, > I wrote a small example, but while running I get an error("Tied to > execute an unknown external function"), where I am wrong? > > Thanks in advance. > Kirill. > > int some_test_func( int ){ > std::cout << "!!!!" << std::endl; > return 8848; > } > > int _tmain(int argc, _TCHAR* argv[]){ > > Module *M = new Module("test"); > ExistingModuleProvider* MP = new ExistingModuleProvider(M); > ExecutionEngine* EE = ExecutionEngine::create(MP, false); > > std::vector<const Type *> func_args; > func_args.push_back(Type::Int32Ty); > FunctionType * func_type = FunctionType::get(Type::Int32Ty, > func_args, false); > Function * my_function = Function::Create( func_type, > Function::ExternalLinkage, "some_test_func", M ); > EE->addGlobalMapping( my_function, (void*)&some_test_func ); > > Function *FooF = cast<Function>(M->getOrInsertFunction("foo", > Type::Int32Ty, (Type *)0)); > BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); > Value *Ten = ConstantInt::get(Type::Int32Ty, 10); > CallInst *Add1CallRes = CallInst::Create(my_function, Ten, > "some_test_func", BB); > Add1CallRes->setTailCall(true); > > ReturnInst::Create(Add1CallRes, BB); > > std::cout << "We just constructed this LLVM module:\n\n" << *M; > std::cout << "\n\nRunning foo: " << std::flush; > > std::vector<GenericValue> noargs; > GenericValue gv = EE->runFunction(FooF, noargs); > > std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << > "\n"; > return 0; > } > > > > 2008/8/19, Gordon Henriksen <gordonhenriksen at me.com>: > > > > On Aug 19, 2008, at 13:36, kirill havok wrote: > > > > I got very interested in LLVM project, and I decided to start writing > my own > > scripting language based on it. By studying the documentation, I > could not > > find how to call external function, written in C. That is, I have a > set of > > functions written in C/C++, I generate code, using LLVM C++ interface, > how > > can I call(or register in machine in run-time) my external functions? > Maybe > > I just missed something. Please, give in which direction to search. > > > > Hi Kirill, > > > > Since LLVM goes to the bare metal, there is no need for an "FFI" or > bindings > > to call native code. Simply create a declaration for the function-a > Function > > with no body-and call it as any other function in your program. (Also, > of > > course, link with a library to define the symbols.) It might be > instructive > > to examine the llvm-gcc -S -emit-llvm output of a program like this: > > > > int MyExternalFn(int, int, int); > > > > int main(int, const char**, const char**) { > > return MyExternalFn(1, 2, 3); > > } > > > > > > Where you tweak MyExternalFn to have the desired prototype. > > > > To create a function declaration: > > > > > > From C++, simply call Function::Create and then do not add any basic > blocks. > > From LLVM assembly, use the keyword "declare" instead of "define": > > http://llvm.org/docs/LangRef.html#functionstructure > > > > > > If you're using the JIT, you'll need to do the above, but also may > need to > > register your functions using > > ExecutionEngine::addGlobalMapping. > > > > http://llvm.org/doxygen/classllvm_1_1ExecutionEngine.html#a8 > > > > > > Note that the C calling convention do not map directly to LLVM IR for > many > > cases, so it's best to stick to simple parameter types (pointers and > ints, > > for example) and also to verify that the LLVM FunctionTypes you use > are > > correct on each platform you support. > > > > Good luck! > > > > - Gordon > > > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Many thanks to all, I really forgot to link with X86TargetMachine.obj file (((((, now this code works perfect. ))))) Sincerely, Kirill int some_test_func( int ){ std::cout << "!!!!" << std::endl; return 8848; } int _tmain(int argc, _TCHAR* argv[]){ Module *M = new Module("test"); ExistingModuleProvider* MP = new ExistingModuleProvider(M); ExecutionEngine* EE = ExecutionEngine::create(MP, false); std::vector<const Type *> func_args; func_args.push_back(Type::Int32Ty); FunctionType * func_type = FunctionType::get(Type::Int32Ty, func_args, false); Function * my_function = Function::Create( func_type, Function::ExternalLinkage, "some_test_func", M ); EE->addGlobalMapping( my_function, (void*)&some_test_func ); Function *FooF = cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); Value *Ten = ConstantInt::get(Type::Int32Ty, 10); CallInst *Add1CallRes = CallInst::Create(my_function, Ten, "some_test_func", BB); Add1CallRes->setTailCall(true); ReturnInst::Create(Add1CallRes, BB); std::cout << "We just constructed this LLVM module:\n\n" << *M; std::cout << "\n\nRunning foo: " << std::flush; std::vector<GenericValue> noargs; GenericValue gv = EE->runFunction(FooF, noargs); std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; return 0; } 2008/8/20 Rob Grapes <Rob.Grapes at ur.co.nz>:> Hi Kirill, > > Don't forget to add X86TargetMachine.obj (add to Additional Dependencies in Linker options, if you are using MSVS) otherwise LLVM will try and use Interpreter instead of JIT. > > Hope this helps, > > Rob. > >> -----Original Message----- >> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] >> On Behalf Of kirill havok >> Sent: Wednesday, August 20, 2008 8:32 AM >> To: LLVM Developers Mailing List >> Subject: Re: [LLVMdev] Please help with LLVM C++ integration >> >> Hi Gordon, >> I wrote a small example, but while running I get an error("Tied to >> execute an unknown external function"), where I am wrong? >> >> Thanks in advance. >> Kirill. >> >> int some_test_func( int ){ >> std::cout << "!!!!" << std::endl; >> return 8848; >> } >> >> int _tmain(int argc, _TCHAR* argv[]){ >> >> Module *M = new Module("test"); >> ExistingModuleProvider* MP = new ExistingModuleProvider(M); >> ExecutionEngine* EE = ExecutionEngine::create(MP, false); >> >> std::vector<const Type *> func_args; >> func_args.push_back(Type::Int32Ty); >> FunctionType * func_type = FunctionType::get(Type::Int32Ty, >> func_args, false); >> Function * my_function = Function::Create( func_type, >> Function::ExternalLinkage, "some_test_func", M ); >> EE->addGlobalMapping( my_function, (void*)&some_test_func ); >> >> Function *FooF = cast<Function>(M->getOrInsertFunction("foo", >> Type::Int32Ty, (Type *)0)); >> BasicBlock * BB = BasicBlock::Create("EntryBlock", FooF); >> Value *Ten = ConstantInt::get(Type::Int32Ty, 10); >> CallInst *Add1CallRes = CallInst::Create(my_function, Ten, >> "some_test_func", BB); >> Add1CallRes->setTailCall(true); >> >> ReturnInst::Create(Add1CallRes, BB); >> >> std::cout << "We just constructed this LLVM module:\n\n" << *M; >> std::cout << "\n\nRunning foo: " << std::flush; >> >> std::vector<GenericValue> noargs; >> GenericValue gv = EE->runFunction(FooF, noargs); >> >> std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << >> "\n"; >> return 0; >> } >> >> >> >> 2008/8/19, Gordon Henriksen <gordonhenriksen at me.com>: >> > >> > On Aug 19, 2008, at 13:36, kirill havok wrote: >> > >> > I got very interested in LLVM project, and I decided to start writing >> my own >> > scripting language based on it. By studying the documentation, I >> could not >> > find how to call external function, written in C. That is, I have a >> set of >> > functions written in C/C++, I generate code, using LLVM C++ interface, >> how >> > can I call(or register in machine in run-time) my external functions? >> Maybe >> > I just missed something. Please, give in which direction to search. >> > >> > Hi Kirill, >> > >> > Since LLVM goes to the bare metal, there is no need for an "FFI" or >> bindings >> > to call native code. Simply create a declaration for the function-a >> Function >> > with no body-and call it as any other function in your program. (Also, >> of >> > course, link with a library to define the symbols.) It might be >> instructive >> > to examine the llvm-gcc -S -emit-llvm output of a program like this: >> > >> > int MyExternalFn(int, int, int); >> > >> > int main(int, const char**, const char**) { >> > return MyExternalFn(1, 2, 3); >> > } >> > >> > >> > Where you tweak MyExternalFn to have the desired prototype. >> > >> > To create a function declaration: >> > >> > >> > From C++, simply call Function::Create and then do not add any basic >> blocks. >> > From LLVM assembly, use the keyword "declare" instead of "define": >> > http://llvm.org/docs/LangRef.html#functionstructure >> > >> > >> > If you're using the JIT, you'll need to do the above, but also may >> need to >> > register your functions using >> > ExecutionEngine::addGlobalMapping. >> > >> > http://llvm.org/doxygen/classllvm_1_1ExecutionEngine.html#a8 >> > >> > >> > Note that the C calling convention do not map directly to LLVM IR for >> many >> > cases, so it's best to stick to simple parameter types (pointers and >> ints, >> > for example) and also to verify that the LLVM FunctionTypes you use >> are >> > correct on each platform you support. >> > >> > Good luck! >> > >> > - Gordon >> > >> > >> > _______________________________________________ >> > LLVM Developers mailing list >> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >> > >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >