Hi, I am trying to insert a instruction for printf or cout. My aim is to print a integer and a string value using that instruction, which are already there in the code. but I am not able to understand how to do it. Any help would be great help. Thanks and Regards, Tarun Agrawal -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120208/dda937d1/attachment.html>
On 2/8/12 11:55 AM, tarun agrawal wrote:> Hi, > > I am trying to insert a instruction for printf or cout. My aim is to > print a integer and a string value using that instruction, which are > already there in the code. > but I am not able to understand how to do it. Any help would be great > help.You want to insert a call instruction that calls the printf function. You'll need to insert a Function for printf (with no body) if no printf function exists within the LLVM module you're transforming. So, the code will look something like: Function * F = M.getOrInsertFunction ("printf", ...); CallInst::Create (F, ...); Be sure to look at the doxygen docs for exact method names and which parameters go where; I've skipped over such details above. -- John T.> > > > Thanks and Regards, > Tarun Agrawal > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120208/fdb11ab1/attachment.html>
Just to be clear, I have to add a function name printf in the module with no body. And I can call the function. This will automatically call the printf function which is defined in the library. Tarun Agrawal On Wed, Feb 8, 2012 at 11:34 PM, John Criswell <criswell at illinois.edu>wrote:> On 2/8/12 11:55 AM, tarun agrawal wrote: > > Hi, > > I am trying to insert a instruction for printf or cout. My aim is to print > a integer and a string value using that instruction, which are already > there in the code. > but I am not able to understand how to do it. Any help would be great help. > > > You want to insert a call instruction that calls the printf function. > You'll need to insert a Function for printf (with no body) if no printf > function exists within the LLVM module you're transforming. > > So, the code will look something like: > > Function * F = M.getOrInsertFunction ("printf", ...); > CallInst::Create (F, ...); > > Be sure to look at the doxygen docs for exact method names and which > parameters go where; I've skipped over such details above. > > -- John T. > > > > > Thanks and Regards, > Tarun Agrawal > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120208/f1d337a7/attachment.html>