Skip to content

Commit 473e342

Browse files
committed
Fix compilation of examples after 1368022 / r352827
Who knew...they're not built by default or as part of the tests. llvm-svn: 352830
1 parent b6c06dc commit 473e342

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

llvm/examples/BrainF/BrainF.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void BrainF::header(LLVMContext& C) {
8282
//Function header
8383

8484
//define void @brainf()
85-
brainf_func = module->getOrInsertFunction("brainf", Type::getVoidTy(C));
85+
brainf_func = Function::Create(FunctionType::get(Type::getVoidTy(C), false),
86+
Function::ExternalLinkage, "brainf", module);
8687

8788
builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func));
8889

llvm/examples/BrainF/BrainF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BrainF {
7878
CompileFlags comflag;
7979
std::istream *in;
8080
Module *module;
81-
FunctionCallee brainf_func;
81+
Function *brainf_func;
8282
FunctionCallee getchar_func;
8383
FunctionCallee putchar_func;
8484
Value *ptr_arr;

llvm/examples/BrainF/BrainFDriver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ void addMainFunction(Module *mod) {
7575
FunctionType *main_func_fty = FunctionType::get(
7676
Type::getInt32Ty(mod->getContext()),
7777
{Type::getInt32Ty(mod->getContext()),
78-
Type::getInt8Ty(mod->getContext())->getPointerTo()->getPointerTo()});
78+
Type::getInt8Ty(mod->getContext())->getPointerTo()->getPointerTo()},
79+
false);
7980
Function *main_func =
80-
Function::create(main_func_fty, Function::ExternalLinkage, "main", mod);
81+
Function::Create(main_func_fty, Function::ExternalLinkage, "main", mod);
8182

8283
{
8384
Function::arg_iterator args = main_func->arg_begin();

llvm/examples/ParallelJIT/ParallelJIT.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
using namespace llvm;
4848

4949
static Function* createAdd1(Module *M) {
50+
LLVMContext &Context = M->getContext();
5051
// Create the add1 function entry and insert this entry into module M. The
5152
// function will have a return type of "int" and take an argument of "int".
5253
Function *Add1F =
@@ -56,10 +57,10 @@ static Function* createAdd1(Module *M) {
5657

5758
// Add a basic block to the function. As before, it automatically inserts
5859
// because of the last argument.
59-
BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", Add1F);
60+
BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", Add1F);
6061

6162
// Get pointers to the constant `1'.
62-
Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1);
63+
Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);
6364

6465
// Get pointers to the integer argument of the add1 function...
6566
assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
@@ -70,13 +71,14 @@ static Function* createAdd1(Module *M) {
7071
Instruction *Add = BinaryOperator::CreateAdd(One, ArgX, "addresult", BB);
7172

7273
// Create the return instruction and add it to the basic block
73-
ReturnInst::Create(M->getContext(), Add, BB);
74+
ReturnInst::Create(Context, Add, BB);
7475

7576
// Now, function add1 is ready.
7677
return Add1F;
7778
}
7879

7980
static Function *CreateFibFunction(Module *M) {
81+
LLVMContext &Context = M->getContext();
8082
// Create the fib function and insert it into module M. This function is said
8183
// to return an int and take an int parameter.
8284
FunctionType *FibFTy = FunctionType::get(Type::getInt32Ty(Context),
@@ -85,27 +87,27 @@ static Function *CreateFibFunction(Module *M) {
8587
Function::Create(FibFTy, Function::ExternalLinkage, "fib", M);
8688

8789
// Add a basic block to the function.
88-
BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF);
90+
BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF);
8991

9092
// Get pointers to the constants.
91-
Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1);
92-
Value *Two = ConstantInt::get(Type::getInt32Ty(M->getContext()), 2);
93+
Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);
94+
Value *Two = ConstantInt::get(Type::getInt32Ty(Context), 2);
9395

9496
// Get pointer to the integer argument of the add1 function...
9597
Argument *ArgX = &*FibF->arg_begin(); // Get the arg.
9698
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
9799

98100
// Create the true_block.
99-
BasicBlock *RetBB = BasicBlock::Create(M->getContext(), "return", FibF);
101+
BasicBlock *RetBB = BasicBlock::Create(Context, "return", FibF);
100102
// Create an exit block.
101-
BasicBlock* RecurseBB = BasicBlock::Create(M->getContext(), "recurse", FibF);
103+
BasicBlock *RecurseBB = BasicBlock::Create(Context, "recurse", FibF);
102104

103105
// Create the "if (arg < 2) goto exitbb"
104106
Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
105107
BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
106108

107109
// Create: ret int 1
108-
ReturnInst::Create(M->getContext(), One, RetBB);
110+
ReturnInst::Create(Context, One, RetBB);
109111

110112
// create fib(x-1)
111113
Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB);
@@ -120,7 +122,7 @@ static Function *CreateFibFunction(Module *M) {
120122
BinaryOperator::CreateAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);
121123

122124
// Create the return instruction and add it to the basic block
123-
ReturnInst::Create(M->getContext(), Sum, RecurseBB);
125+
ReturnInst::Create(Context, Sum, RecurseBB);
124126

125127
return FibF;
126128
}

0 commit comments

Comments
 (0)