December 2015
Beginner to intermediate
166 pages
3h 8m
English
A function might return a value or it may return void. Here in our example, we have defined that our function returns an integer. Let's assume that our function returns 0. The first step is to get a 0 value, which can be done using the Constant class.
Builder.CreateRet(Builder.getInt32(0));
The overall code is as follows:
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" #include <vector> using namespace llvm; static LLVMContext &Context = getGlobalContext(); static Module *ModuleOb = new Module("my compiler", Context); Function *createFunc(IRBuilder<> &Builder, std::string Name) { FunctionType *funcType = llvm::FunctionType::get(Builder.getInt32Ty(), ...Read now
Unlock full access