[LLVMdev] inserting a print statement into IR

George Baah georgebaah at gmail.com
Mon Apr 4 17:26:34 PDT 2011


Hi Everyone,
  I am trying to construct the print statement : printf("value:%d\n",
value);
This is my llvm code. It is seg faulting at
builder.CreateGlobalStringPtr(str,"").
Thanks.

George

vector<const Type *> params;
params.push_back(Type::getInt8PtrTy(M.getContext()));
FunctionType *fType =
FunctionType::get(Type::getInt32Ty(M.getContext()), params, true);
Constant *temp = M.getOrInsertFunction("printf",fType);
if(!temp){
  errs() << "printf function not in symbol table\n";
  exit(1);
}
Function *f = cast<Function>(temp);
f->setCallingConv(CallingConv::C);

const char *str = "value: %d\n";
Value *intparam = ...
Value *strPtr = builder.CreateGlobalStringPtr(str,"");
builder.CreateCall2(PrintF, strPtr, intparam,"tmp6");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110404/1ba75642/attachment.html>


More information about the llvm-dev mailing list