[LLVMdev] Instruction for print

John Criswell criswell at illinois.edu
Wed Feb 8 10:15:03 PST 2012

On 2/8/12 12:11 PM, tarun agrawal wrote:
> 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.

Yes.  That is correct.

You also need to link in the native code library that defines printf 
after code generation, but since printf is in libc, you are probably 
doing that step already.

-- John T.

> Tarun Agrawal
> On Wed, Feb 8, 2012 at 11:34 PM, John Criswell <criswell at illinois.edu 
> <mailto: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 list
>>     LLVMdev at cs.uiuc.edu  <mailto: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/30380b7c/attachment.html>

More information about the llvm-dev mailing list