December 2015
Beginner to intermediate
166 pages
3h 8m
English
Now that we have created a module, the next step is to emit a function. LLVM has an IRBuilder class that is used to generate LLVM IR and print it using the dump function of the Module object. LLVM provides the class llvm::Function to create a function and llvm::FunctionType() to associate a return type for the function. Let's assume that our foo() function returns an integer type.
Function *createFunc(IRBuilder<> &Builder, std::string Name) {
FunctionType *funcType = llvm::FunctionType::get(Builder.getInt32Ty(), false);
Function *fooFunc = llvm::Function::Create(
funcType, llvm::Function::ExternalLinkage, Name, ModuleOb);
return fooFunc;
}Finally, call function verifyFunction() on fooFunc. This function performs ...
Read now
Unlock full access