Hello,

I am a Ph.D. student at CMU and use CIL as my front end for C to HW
compilation. In the course of developing my back-end I have encountered
something unexpected that I do not understand.

At one point in the program I collect global variables, merge the with
locals of a given function f and call varsUsesMap as follows:

  let global_vars = List.fold_left (
    fun gv g ->
      match g with
    | GVar (vi,ii,loc) ->
          vi::gv
    | _ -> gv
  ) [] file.globals in

  let (stack,heap,malloc,input,output) =
    varsUsesMap (global_vars @ f.slocals) i_channels o_channels in ...

The body of function varsUsesMap with some extra debugging printf()s is:

let varsUsesMap (vars:varinfo list) (ic:varinfo list) (oc:varinfo list) =
  let _ = if !debug then
    Printf.printf "varUsesMap() called\n" in
  let output = List.map (fun c -> (c,ref [])) oc in
  let input = List.map (fun c -> (c,ref [])) ic in
  let malloc = List.map (fun t -> (t,ref [])) (TS.elements !types) in
  let heap = List.map (fun t -> (t,ref [])) (TS.elements !types) in
  let stack = List.map (fun v -> (v,ref [])) vars in

  let _ = List.iter (
    fun vi ->
    Printf.printf "%s %d\n" vi.vname vi.vid
  ) vars in

  let _ = List.iter (
    fun (x,x_node) ->
      match x_node.typ with
    | Instruction i ->
        let _ = if !debug then Pretty.fprint stdout 80
          (Cil.printInstr Cil.plainCilPrinter () i) in
        let _ = if !debug then Printf.printf "\n" in
        let id = x_node.id in
          (try
         (match i with
              Cil.Set((Cil.Var v, off),exp,loc) ->
            let _ = Printf.printf "!!!%s %d\n" v.vname v.vid in
              (List.assoc v stack) := (id::!(List.assoc v stack)) // This
returns the Not_found for ma_list_index
           ...
    | _ -> ()
  ) !nodes in
    (stack,heap,malloc,input,output)

When varsUsesMap processes a function with a global (say ma_list_index), it
produces the following output:

varUsesMap() called
ma_list_index 734
ma_list 733
k 1498
one 1499
tmp 1500
c 1501
buffer 1502
tmp___0 1505
sorted_insert1_data 1515
sorted_insert1_l 1516
sorted_insert1_elem 1517
sorted_insert1_prev 1518
sorted_insert1_x 1519
sorted_insert1_b 1520
!!!ma_list_index 1482

and generation a Not_found exception.

It puzzles me that the varinfo in the function's body does not have the same
variable id as the global variable varinfo. Note that there is no local
variable with that name in my program.

I would be very grateful for any advice that can help me deal with this
issue. Thanks.

Best,

-- 
Jiri Simsa
Ph.D. Student
Carnegie Mellon University
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to