[LLVMdev] LLVM-Kaleidoscope tutorial

Remy Demarest remy.demarest at gmail.com
Sat Oct 3 05:04:11 PDT 2009


Good morning everyone,

It seems the LLVM tutorial is not up to date anymore and doesn't  
compile as is...

The function makeLLVMModule() function doesn't compile at all. Here is  
a fix:

Module *makeLLVMModule()
{
     // Caches the global context to share it with new Module() and  
IntegerType::get() calls
     LLVMContext &context = getGlobalContext();

     // Module Construction
     Module *mod = new Module("test", context);

     Constant *c = mod->getOrInsertFunction("mul_add",
                                            // IntegerType::get 
(context, 32) instead of IntegerType::get(32)
                                            IntegerType::get(context,  
32), // Return type
                                            IntegerType::get(context,  
32), // Arguments
                                            IntegerType::get(context,  
32),
                                            IntegerType::get(context,  
32),
                                             
NULL                           // Varargs terminated with NULL
                                            );

     Function* mul_add = cast<Function>(c);
     mul_add->setCallingConv(CallingConv::C);
     Function::arg_iterator args = mul_add->arg_begin();
     Value *x = args++;
     x->setName("x");
     Value *y = args++;
     y->setName("y");
     Value *z = args++;
     z->setName("z");
     BasicBlock *block = BasicBlock::Create(getGlobalContext(),  
"entry", mul_add);
     IRBuilder<> builder(block);
     Value *tmp = builder.CreateBinOp(Instruction::Mul,
                                      x, y, "tmp");
     Value *tmp2 = builder.CreateBinOp(Instruction::Add,
                                       tmp, z, "tmp2");

     builder.CreateRet(tmp2);

     return mod;
}

__________________________
Remy Demarest
remy.demarest at gmail.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091003/045f77c9/attachment.html>


More information about the llvm-dev mailing list