I'm trying to implement the following functionality;
- a function with no explicit return will by default return the last evaluation in the last executed block
So, currently the process i'm doing is
1) create a Function
llvm::Function* result = llvm::Function::Create(Compiler::Detail::getAnonymousFunctionSignature(llvmContext),
llvm::GlobalValue::ExternalLinkage,
name,
module());
result->setCallingConv( llvm::CallingConv::C );
2) add blocks and evaluations to the blocks
builder.createFoo.....
However, only in the second phase i have the llvm::Value* (and compile-time type) that i want to use by default as return value. The problem is that i need to use this type to determine the signature of the created function
Question:
how do i solve the problem?
- is possible to change the signature after the function is created? is it legal?
- do i need to create a new function with the updated signature and copy/assign the entry block of the first function to it and thats it? or do i need to reevaluate all the expressions?
- is possible to not create the function before code generation? if it is so, at what point should i create the function?
a code example of how to achieve this would be awesome. thanks!