A function takes arguments that have their own data type. For simplification, assume that our function has all the arguments of i32 type (integer 32 bit).
For example, we will consider that two arguments, a and b, are passed to the function. We will store these two arguments in a vector:
static std::vector <std::string> FunArgs;
FunArgs.push_back("a");
FunArgs.push_back("b");
The next step is to specify that the function will have two arguments. This can be done by passing the Integer argument to the functiontype
.
Function *createFunc(IRBuilder<> &Builder, std::string Name) {
std::vector<Type *> Integers(FunArgs.size(), Type::getInt32Ty(Context));
FunctionType *funcType =
llvm::FunctionType::get(Builder.getInt32Ty(), Integers, false);
Function *fooFunc = llvm::Function::Create(
funcType, llvm::Function::ExternalLinkage, Name, ModuleOb);
return fooFunc;
}
The last step is to set the names of the function arguments. This...