[LLVMdev] Figuring out the parameters of the Call Instruction

shankha shankhabanerjee at gmail.com
Wed Jul 14 11:41:06 PDT 2010


Hi,
I am trying to figure out how to read arguments of a call instruction.
I had few questions based on that

I have the following C Code

  1 #include <stdio.h>
  2
  3 struct my_struct
  4 {
  5    int a;
  6    int b;
  7 };
  8
  9 struct my_struct abc;
 10 void p_ptr ( unsigned long j)
 11 {
 12    printf ( "%lx \n", j );
 13 }
 14
 15 void struct_ptr ( struct my_struct * s_ptr )
 16 {
 17    printf ( "%p \n", s_ptr );
 18 }
 19
 20 int
 21 main ()
 22 {
 23    struct my_struct stack_abc;

 24    p_ptr ((unsigned long) &abc);
 25    struct_ptr ( &abc );
 26    p_ptr ((unsigned long) &stack_abc);
 27    struct_ptr ( &stack_abc );

 28    return 0;
 29 }

  24    p_ptr ((unsigned long) &abc);
  call void @p_ptr(i64 ptrtoint (%struct.my_struct* @abc to i64))
nounwind, !dbg !31

  Q.1  At line no 24 I try to read the address of global variable abc.
The address is type casted
         from struct * to int * for which ptrtoint. I read the
operands of the call instruction and there
         descriptions. I do not see among the fields of the call
instruction the ptrtoint instruction.
         How can I reach the ptrtoint instruction from the call
instruction ? What fields I need to access.


  26 p_ptr ((unsigned long) &stack_abc);
  %stack_abc1 = ptrtoint %struct.my_struct* %stack_abc to i64, !dbg
!33 ; <i64> [#uses=1]
  call void @p_ptr(i64 %stack_abc1) nounwind, !dbg !33

  Q.2  stack_abc1 is a alias for the operation performed by the
ptrtoint instruction.
         Which fields from the instruction class will help me read if I may say
         the "output" of the instruction ?


Thanks
Shankha Banerjee



More information about the llvm-dev mailing list