LLVM-Kaleidoscope tutorial

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(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;
}

The Kaleidoscope in the source tree is correct, but the web page is
not updated as often. Lots has changed since and you should use the
source on:

llvm/examples/Kaleidoscope

which compiles to:

llvm/Debug/examples

cheers,
--renato

Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm