Thanks for the example.

 let convert v = Lval (Var v.svar, NoOffset) in
        mkStmtOneInstr (Call(None, convert foo, [f; 1], loc));

In the above code i am getting following error:


Error: This expression has type Cil.varinfo
       but an expression was expected of type Cil.fundec

where "foo" is type of varinfo

also findOrCreateFunc finds a function definition inside the input file to
be instrumented ? if yes then what if the function definition for which
call is to be inserted is saved in a separate file.

Regards
Sonam


> On Sat, Mar 02, 2013 at 08:40:39PM +0530, son...@iitk.ac.in wrote:
>> But i am not able to create a call statement along with parameters
>> (arguments)
>> any simple example would be helpful.
>
> Example to create:
>   int tmp = foo(1, 2);
> inside a function bar (assuming [foo] and [bar] are of type fundec, you
> can find
> them with a visitor or build them with findOrCreateFunc).
>
> let build_call_stmt (foo: fundec) (bar: fundec) =
>   (* variable holding the return value of the call *)
>   let r = makeTempVar bar intType in
>   let ret = (Var r, NoOffset) in
>   (* the function foo *)
>   let f = Lval (Var foo.svar, NoOffset) in
>   (* the arguments: 1, 2 *)
>   let args = [integer 1; integer 2] in
>   (* everything together *)
>   let call = Call (Some ret, f, args, locUnknown) in
>   mkStmtOneInstr call
>
> Example use of findOrCreateFunc:
>
> let find_foo () =
>   (* foo is of type int (*foo)(int a, int b) *)
>   let foo_type = TFun (
>     intType,              (* return type *)
>     Some [                (* arguments *)
>       ("a", integer, []);
>       ("b", integer, [])
>       ],
>     false,                 (* foo is NOT variadic *)
>     []                     (* foo has not attributes *)
>     ) in
>   findOrCreateFunc file "foo" foo_type
>
> (None of this has been tested, there might be a few typos, but you get the
> idea.)
>
> Hope it helps,
> --
> Gabriel
>


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to