-
Notifications
You must be signed in to change notification settings - Fork 1
/
chapter02-3.cpp
36 lines (28 loc) · 964 Bytes
/
chapter02-3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Verifier.h"
#include <vector>
using namespace llvm;
static LLVMContext Context;
static Module *ModuleOb = new Module("my compiler", Context);
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;
}
BasicBlock *createBB(Function *fooFunc, std::string Name) {
return BasicBlock::Create(Context, Name, fooFunc);
}
int main(int argc, char *argv[])
{
//ModuleOb->dump();
static IRBuilder<> Builder(Context);
Function *fooFunc = createFunc(Builder, "foo");
BasicBlock *entry = createBB(fooFunc, "entry");
Builder.SetInsertPoint(entry);
verifyFunction(*fooFunc);
ModuleOb->print(llvm::outs(), nullptr);
return 0;
}