[LLVMdev] How to get the name and argument of a function

songlh at cs.wisc.edu songlh at cs.wisc.edu
Mon Jan 17 14:37:51 PST 2011


Hi everyone:

   The code I am analyzing is :

   int main()
   {
       int i = 0;
       printf("hello world!");
       printf( "%d" , i );
   }



   I want to get each place where printf is called, and the argument used
during that call.

   so I write llvm pass code like:

   void Myfunction( Function & F){
       for( Function::iterator b = F.begin() , be = F.end() ;
        b != be; ++b){
           for(BasicBlock::iterator i = b.begin() , ie = b.end();
            i != ie; i ++){
               if( isa<CallInst>(&(*i)) || isa<InvokeInst>(&(*i))){
                   //how could I get the function name and argument
                   //used here
               }
           }

       }
   }


   How could I get the function name and the arguments when I know an
Instruction is a function call?

   thanks a lot!

   Best wishes!

                                                 Linhai Song




More information about the llvm-dev mailing list