May 2015
Intermediate to advanced
296 pages
5h 10m
English
In this recipe you, will learn how to generate IR code for a function.
Do the following steps:
Codegen() function for the function call can be defined as follows:Value *FunctionCallAST::Codegen() {
Function *CalleeF =
Module_Ob->getFunction(Function_Callee);
std::vector<Value*>ArgsV;
for(unsigned i = 0, e = Function_Arguments.size();
i != e; ++i) {
ArgsV.push_back(Function_Arguments[i]->Codegen());
if(ArgsV.back() == 0) return 0;
}
return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
}Once we have the function to call, we recursively call the Codegen() function for each argument that is to be passed in and create an LLVM call instruction.
Codegen() function for a function call has been ...Read now
Unlock full access