Thanks for these quick responses !


VN -


On Thu, Apr 8, 2010 at 9:19 AM, Elnatan Reisner <elna...@cs.umd.edu> wrote:

> On Apr 8, 2010, at 10:46 AM, ThanhVu (Vu) Nguyen wrote:
>
> let's say I want to add a statement  s1  (e.g.,  printf("hello world");)
> before every IF in the code.  I created an instrumenter with CIL that
> basically does mkStmt(Block(mkBlock([s1 ; if_stuff]))) .
>
> It works out well in most case except the below :
>
> switch (something){
> case something1:
>     if(cond1){ ...  }
>     break;
>     if(cond2){ ... }
>     break;
> }
>
> applying the instrumenter  gives this result
>
> switch (something){
>
> s1;
> case something1:
>     if(cond1){  }
>     break;
>
> s1;
> case something2:
>     if(cond2){
>     }
>     break;
> }
>
> Thus, the new statements (s1,s2 ..) added always go above the "case ... "
> instead of after and basically a semantic change ?
>
>
> This is certainly not a bug in CIL; you just need to be careful about how
> you manipulate the program. In this case, you need to move the label from
> the original statement to the statement you are inserting (although I'm not
> sure this is what you'd want to do in all cases). I added a few lines to
> your vstmt method which are meant to do this, but I haven't tested it:
>
>   method vstmt s = ChangeDoChildrenPost(
> s,fun s -> (
>   match s.skind with
>  |If(_,_,_,_) -> (   (*add a hello world before if*)
> let fprintf = Lval((Var (makeVarinfo true "fprintf" (TVoid []))), NoOffset)
> in
>  let hello_str = Const(CStr("hello word ")) in
> let instr = Call(None,fprintf,[hello_str],!currentLoc) in
>  let ns = mkStmtOneInstr(instr) in
> let newStatement = mkStmt(Block(mkBlock([ns;s]))) in
> newStatement.labels <- s.labels;
>  s.labels <- [];
> newStatement
>   )
>
> |_ -> s  (*don't change*)
>
> )
>   )
>
> Elnatan
>
------------------------------------------------------------------------------
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