Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.

Commit 3b47ce8

Browse files
Generate function that takes two ints and returns zero
1 parent 7690ac1 commit 3b47ce8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <llvm/ExecutionEngine/ExecutionEngine.h>
22
#include <llvm/IR/DataLayout.h>
3+
#include <llvm/IR/IRBuilder.h>
34
#include <llvm/IR/LLVMContext.h>
45
#include <llvm/IR/Module.h>
6+
#include <llvm/IR/Verifier.h>
57
#include <llvm/Support/CommandLine.h>
68
#include <llvm/Support/Debug.h>
79
#include <llvm/Support/Error.h>
@@ -19,7 +21,21 @@
1921
using namespace llvm;
2022

2123
Expected<std::string> codegenIR(Module &module, unsigned items) {
22-
return "todo";
24+
LLVMContext &ctx = module.getContext();
25+
IRBuilder<> B(ctx);
26+
27+
auto name = "getZero";
28+
auto returnTy = Type::getInt32Ty(ctx);
29+
auto argTy = Type::getInt32Ty(ctx);
30+
auto signature = FunctionType::get(returnTy, {argTy, argTy}, false);
31+
auto linkage = Function::ExternalLinkage;
32+
33+
auto fn = Function::Create(signature, linkage, name, module);
34+
35+
B.SetInsertPoint(BasicBlock::Create(ctx, "entry", fn));
36+
B.CreateRet(ConstantInt::get(returnTy, 0));
37+
38+
return name;
2339
}
2440

2541
// Determine the size of a C array at compile-time.

0 commit comments

Comments
 (0)