Hi,

On Mon, Mar 15, 2010 at 05:01:09PM -0600, ThanhVu (Vu) Nguyen wrote:
> Hi, I am trying to insert a function call "fun_dummy"  at each branch of an
> if-else statement but facing some problems.  Hope someone can help.   TIA  
> [...]
> Below lists my code,   the problem with this is that it only gives me
>  foo_dummy(b,100)  and doesn't give foo_dummy(a,10) -- I suspect this is due 
> to
> the way I do the visitor   
> 
> 
> (*** instrumenter ***)
> let dummy = "dummy"
> let dummy_ctr = ref 0
> 
> let dummy_foo_va fn = 
>   incr dummy_ctr;
>   makeVarinfo true (fn^"_"^dummy^soi(!dummy_ctr))  (TVoid [])
> 
> 
> let dummy_foo fn = Lval((Var (dummy_foo_va fn)),nos)
> 
> class instrumenter()= object
>   inherit nopCilVisitor
>   val funname = ref ""
>   val args = ref []
>   val enter_if = ref false

Use mutable instead of ref here:
    val mutable funname = ""
    val mutable args = []
    val mutable enter_if = false

>   method vfunc fd = (
> funname := fd.svar.vname;
> debug "Entering function \'%s\':\n" !funname;
> DoChildren
>   )
>   method vstmt s =

I would rather use ChangeDoChildrenPost and add the statements here
(thus removing the vblock method).

match s.skind with 
 |If(BinOp(_,e1,e2,_),_,_,_)->
 debug "If statement encounter!\n";
 enter_if := true;
 ChangeDoChildrenPost(s, fun s -> match s.skind with
    | If(op,b1,b2,loc) ->
        let x = ... e1 ... in (* build whatever you want depending on *)
        let y = ... e2 ... in (* e1 and e2. *)
        If(op, { b1 with bstmts = ... }, (* do whatever you want here *)
               { b2 with bstmts = ... }, (* same here *)
               loc)
    | _ -> E.s (E.bug "unexpected statement returned")
 )

(* You problem was here: you need to go down into other statements, not
 skip them: *)
 |_-> DoChildren
> end

Regards,
-- 
Gabriel Kerneis

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to