inserting a function into a module

I'm looking for an example of how to insert a new function into a module.

I have a module pass that needs to create some new functions.

Tia.

Reed

Grep any LLVM code for Function::Create

For example:

https://hpcforge.org/scm/viewvc.php/checkout/trunk/src/runtime/Wrappers.cpp?root=kernelgen

// The host call launcher prototype to be added
// to entire module.
Module* m = call->getParent()->getParent()->getParent();
Function* hostcall = m->getFunction(“kernelgen_hostcall”);
if (!hostcall)
hostcall = Function::Create(
TypeBuilder<void(types::i<8>, types::i<64>,
types::i<64>, types::i<32>
), true>::get(context),
GlobalValue::ExternalLinkage, “kernelgen_hostcall”, m);

2013/4/19 reed kotler <rkotler@mips.com>

Your query should be adequately covered by:

http://llvm.org/docs/tutorial/LangImpl3.html#function-code-generation

– Sean Silva

I'm looking for an example of how to insert a new function into a module.

You'll create a function declaration (i.e., an empty function) and then add basic blocks to it.

I believe this code from SAFECode (http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/lib/OptimizeChecks/InlineFastChecks.cpp?revision=168085&view=markup) may provide an example (caveat: it works with LLVM 3.2).

-- John T.