2 * Computes iterator-loop nesting depths and max depth of each function.
8 let log cx = Session.log "loop"
9 cx.ctxt_sess.Session.sess_log_loop
10 cx.ctxt_sess.Session.sess_log_out
13 type fn_ctxt = { current_depth: int; }
16 let incr_depth (fcx:fn_ctxt) =
17 { current_depth = fcx.current_depth + 1; }
20 let decr_depth (fcx:fn_ctxt) =
21 { current_depth = fcx.current_depth - 1; }
24 let top_fcx = { current_depth = 0; }
27 let loop_depth_visitor
32 let (fcxs : fn_ctxt Stack.t) = Stack.create () in
35 let fcx = Stack.pop fcxs in
36 Stack.push (incr_depth fcx) fcxs
40 let fcx = Stack.pop fcxs in
41 Stack.push (decr_depth fcx) fcxs
44 let visit_mod_item_pre
46 (ty_params:(Ast.ty_param identified) array)
49 Stack.push top_fcx fcxs;
50 inner.Walk.visit_mod_item_pre ident ty_params item
53 let visit_mod_item_post
55 (ty_params:(Ast.ty_param identified) array)
58 inner.Walk.visit_mod_item_post ident ty_params item;
59 ignore (Stack.pop fcxs);
63 (obj:Ast.obj identified)
65 (fn:Ast.fn identified)
67 Stack.push top_fcx fcxs;
68 inner.Walk.visit_obj_fn_pre obj ident fn
72 (obj:Ast.obj identified)
74 (fn:Ast.fn identified)
76 inner.Walk.visit_obj_fn_pre obj ident fn;
77 ignore (Stack.pop fcxs)
80 let visit_obj_drop_pre
81 (obj:Ast.obj identified)
84 Stack.push top_fcx fcxs;
85 inner.Walk.visit_obj_drop_pre obj b
88 let visit_obj_drop_post
89 (obj:Ast.obj identified)
92 inner.Walk.visit_obj_drop_post obj b;
93 ignore (Stack.pop fcxs)
96 let visit_slot_identified_pre sloti =
97 let fcx = Stack.top fcxs in
98 htab_put cx.ctxt_slot_loop_depths sloti.id fcx.current_depth;
99 inner.Walk.visit_slot_identified_pre sloti
102 let visit_stmt_pre s =
103 let fcx = Stack.top fcxs in
104 htab_put cx.ctxt_stmt_loop_depths s.id fcx.current_depth;
107 | Ast.STMT_for_each fe ->
108 htab_put cx.ctxt_block_is_loop_body fe.Ast.for_each_body.id ();
111 inner.Walk.visit_stmt_pre s
114 let visit_block_pre b =
115 if Hashtbl.mem cx.ctxt_block_is_loop_body b.id
117 inner.Walk.visit_block_pre b
120 let visit_block_post b =
121 inner.Walk.visit_block_post b;
122 if Hashtbl.mem cx.ctxt_block_is_loop_body b.id
127 Walk.visit_mod_item_pre = visit_mod_item_pre;
128 Walk.visit_mod_item_post = visit_mod_item_post;
129 Walk.visit_obj_fn_pre = visit_obj_fn_pre;
130 Walk.visit_obj_fn_post = visit_obj_fn_post;
131 Walk.visit_obj_drop_pre = visit_obj_drop_pre;
132 Walk.visit_obj_drop_post = visit_obj_drop_post;
133 Walk.visit_slot_identified_pre = visit_slot_identified_pre;
134 Walk.visit_stmt_pre = visit_stmt_pre;
135 Walk.visit_block_pre = visit_block_pre;
136 Walk.visit_block_post = visit_block_post }
143 let path = Stack.create () in
146 (loop_depth_visitor cx
151 run_passes cx "loop" path passes (log cx "%s") crate;
159 * indent-tabs-mode: nil
160 * buffer-file-coding-system: utf-8-unix
161 * compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";