Hi,

On Thu, Apr 08, 2010 at 08:46:22AM -0600, ThanhVu (Vu) Nguyen wrote:
> Is this a bug in CIL or there's some other way to do what I want ?    TIA

Statement cases are labels. You have to copy them as well if you want
them to be in the right place (or modify the statement in place, see
below):

> open Printf
> open Cil
> class instrumenter () = object
>   inherit nopCilVisitor
> 
>       
>   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
        (* copy s, clearing the labels, and add ns before *)
        s.skind <- Block(mkBlock([ns; { s with labels = []} ])));
        s
>                 )
> 
>               |_ -> s  (*don't change*)
>                  
>       )
>   )
> end

Not tested, but it should work.  Despite being implemented in a
functional language, CIL is heavily imperative (for efficiency reasons I
guess), which makes it tricky to get right sometimes (sharing etc. must
be preserved).

Regards,
-- 
Gabriel

------------------------------------------------------------------------------
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