

Ocaml code - vishnupriya

open Ssa<p>module H = Hashtbl.Make(Ssa.G.V)
module VH = Vine.VarHash
module PDG = Vine_pdg.SSA_PDG<p>let in_slice ?(keep_asserts=true) cfg variables =
  let pdg = PDG.compute_pdg cfg in
  let live = H.create cfg#length in
  let is_live = H.mem live in
  let rec add_to_slice id =
    if not(is_live id) then (
      H.add live id ();
      PDG.iter_pred add_to_slice pdg id
    )
  in
  let vh = VH.create (List.length variables) in
  let () = List.iter (fun x -&#62; VH.add vh x ()) variables in
  let rec live_stmt = function
    | Attr(s,_) -&#62; live_stmt s
    | Move(v,_) -&#62; VH.mem vh v
    | Assert _ -&#62; keep_asserts
    | Label _
    | Comment _ -&#62; true
    | _ -&#62; false
  in
  let live_bb bb =
    List.exists live_stmt (cfg#get_info bb)
  in
    cfg#iter_bb (fun bb -&#62; if live_bb bb then add_to_slice (cfg#get_id bb));
    add_to_slice Vine_cfg.BB_Exit;
    is_live<p>let slice ?(keep_asserts=false) cfg variables =
  let id_live = in_slice ~keep_asserts:keep_asserts cfg variables in
  let bb_dead bb = not(id_live (cfg#get_id bb)) in
  let for_later = ref [] in
  let remove_simple bb =
    let action = match cfg#succ bb with
      | [s] -&#62; `Remove s
      | [s;s'] when s = s' -&#62; `Remove s
      | [s;s'] when s' = bb -&#62; `Remove s
      | [s';s] when s' = bb -&#62; `Remove s
      | [] -&#62; `Drop
      | _ -&#62; `Postpone
    in
      match action with
	| `Remove s -&#62;
	    cfg#iter_pred (fun p -&#62; cfg#add_edge p s) bb;
	    cfg#remove_bb bb
	| `Drop -&#62;
	    cfg#remove_bb bb
	| `Postpone -&#62;
	    for_later :=  bb :: !for_later
  in
    cfg#iter_bb (fun bb -&#62; if bb_dead bb then remove_simple bb);
    while !for_later &#60;&#62; [] do
      let toremove = !for_later in
      let size = cfg#length in
	for_later := [];
	List.iter remove_simple toremove;
	(* Hmm, there exist cases this won't be able to deal with... 
	   Would requiring reducible loops be enough? *)
	assert(size &#60;&#62; cfg#length)
    done<p>can anyone explain this part of code??
======
ithkuil
I'd suggest you to paste it into something like <http://pastebin.com/> with
syntax highlighting and proper formatting otherwise no one is going to take a
look

~~~
vishnupriya
thnk yu.

