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

Commit

Permalink
Generate function that takes two ints and returns zero
Browse files Browse the repository at this point in the history
  • Loading branch information
weliveindetail committed Dec 8, 2019
1 parent 7690ac1 commit 3b47ce8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main.cpp
@@ -1,7 +1,9 @@
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/Debug.h>
#include <llvm/Support/Error.h>
Expand All @@ -19,7 +21,21 @@
using namespace llvm;

Expected<std::string> codegenIR(Module &module, unsigned items) {
return "todo";
LLVMContext &ctx = module.getContext();
IRBuilder<> B(ctx);

auto name = "getZero";
auto returnTy = Type::getInt32Ty(ctx);
auto argTy = Type::getInt32Ty(ctx);
auto signature = FunctionType::get(returnTy, {argTy, argTy}, false);
auto linkage = Function::ExternalLinkage;

auto fn = Function::Create(signature, linkage, name, module);

B.SetInsertPoint(BasicBlock::Create(ctx, "entry", fn));
B.CreateRet(ConstantInt::get(returnTy, 0));

return name;
}

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

0 comments on commit 3b47ce8

Please sign in to comment.