[LLVMdev] insert printf into IR

George Baah georgebaah at gmail.com
Thu Mar 31 22:46:50 PDT 2011


Hi All,
  I am trying to insert printf ("%d", v), where v is an integer param, into
the IR.
I am doing something wrong because I keep getting segfaults.
Below is my code. Thanks.


vector<const Type *> params;
params.push_back(Type::getInt8PtrTy(M.getContext()));
params.push_back(Type::getInt32Ty(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);

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/20110401/cecae798/attachment.html>


More information about the llvm-dev mailing list