Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
* main_codeslicer.ml: generate list of files, first approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
pad committed Sep 18, 2014
1 parent af3e9b8 commit 99bd2ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion graph_code/graph_code_database.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ let db_of_graph_code root g =
let hdirs = Hashtbl.create 101 in

(* opti: using G.parent and check if G.not_found is slow *)
let hnot_found = G.all_children G.not_found g +> Common.hashset_of_list in
let hnot_found =
G.node_and_all_children G.not_found g +> Common.hashset_of_list in
(* opti: using G.pred is super slow *)
let use_pred = G.mk_eff_use_pred g in

Expand Down
1 change: 1 addition & 0 deletions graph_code/graph_code_opti.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ let children n g =
g.i_to_name.(i)
)

(* todo? does it include n? *)
let all_children n g =

let rec aux i =
Expand Down
42 changes: 38 additions & 4 deletions main_codeslicer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ let find_big_branching_factor graph_file =
+> List.map (fun parent -> Graph.succ parent hierarchy)
+> List.flatten
(* transitive closure to also remove the fields, methods of a class *)
+> List.map (fun node -> node::Graph_code.all_children node g)
+> List.map (fun node -> Graph_code.node_and_all_children node g)
+> List.flatten
+> Common.hashset_of_list
in
Expand All @@ -442,7 +442,7 @@ let find_big_branching_factor graph_file =
in

let make_live node =
let xs = node::Graph_code.all_children node g in
let xs = Graph_code.node_and_all_children node g in
xs +> List.iter (fun node ->
Hashtbl.remove hdead_candidates node;
Common.push node live
Expand Down Expand Up @@ -475,7 +475,7 @@ let find_big_branching_factor graph_file =
let dead = ref (Common.hashset_to_list hdead_candidates) in

let make_dead node =
let xs = node::Graph_code.all_children node g in
let xs = Graph_code.node_and_all_children node g in
xs +> List.iter (fun node ->
Hashtbl.replace hdead_candidates node true;
Common.push node dead
Expand All @@ -495,7 +495,7 @@ let find_big_branching_factor graph_file =
live_uses_of_dead_code +> List.iter (fun live_use_of_dead_node ->
let xs =
let node = live_use_of_dead_node in
node::Graph_code.all_children node g
Graph_code.node_and_all_children node g
in
let hxs = Common.hashset_of_list xs in

Expand All @@ -515,6 +515,40 @@ let find_big_branching_factor graph_file =
pr2 (spf "step4: candidates for removal = %d"
(Hashtbl.length hdead_candidates));

(* debug
hdead_candidates +> Common.hashset_to_list +> List.iter (fun node ->
pr (spf "DEAD: %s" (Graph_code.string_of_node node))
);
*)

(* step5: slice the code! *)

(* first approximation *)
let files_to_remove =
Graph_code.all_nodes g +> Common.map_filter (fun node ->
match node with
| filename, Entity_code.File ->
(* ? should look for all children recursively? *)
let children = Graph_code.children node g in

(* debug
if filename =~ ".*AbstractDirectedGraphTestCase" then begin
children +> List.iter (fun child ->
if not (Hashtbl.mem hdead_candidates child)
then pr2_gen child
)
end;
*)
if children +> List.for_all (fun node ->
Hashtbl.mem hdead_candidates node
)
then Some filename
else None
| _ -> None
)
in
files_to_remove +> List.iter pr;

()


Expand Down

0 comments on commit 99bd2ae

Please sign in to comment.