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

For example

original code

foo(){

if (a > 10){
    if (b < 100){
    }
    else{
    }
}
else{

}

}//end foo

becomes

foo(){

if (a > 10){
       foo_dummy(a,10)
    if (b == 100){
       foo_dummy(b,100)
    }
    else{
       foo_dummy(b,100)
    }
}
else{
    foo_dummy(a,10)
}

}//end foo



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
  method vfunc fd = (
funname := fd.svar.vname;
debug "Entering function \'%s\':\n" !funname;
 DoChildren
  )
   method vstmt s = (
match s.skind with
  |If(cond,b1,b2,_)->(
  debug "If statement encounter!\n";
  enter_if := true;

  args:= (match cond with
|BinOp(_,exp1,exp2,_) -> [exp1;exp2]
|_ -> []
 );
  DoChildren
)
  |_->SkipChildren
  )


  method vblock b = ChangeDoChildrenPost(
b,fun b when !enter_if -> (
  let stmt1=Call(None,(dummy_foo !funname),!args,!currentLoc) in
  let mystmt = mkStmt(Instr[stmt1]) in
  {b with bstmts = mystmt::b.bstmts}
))

end


VN -
------------------------------------------------------------------------------
Download Intel&#174; 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