1 | type node = Label.t |
---|
2 | type statement = RTL.statement |
---|
3 | |
---|
4 | module NodeMap = Label.Map |
---|
5 | module NodeSet = Label.Set |
---|
6 | |
---|
7 | open RTL |
---|
8 | |
---|
9 | type t = graph |
---|
10 | |
---|
11 | let successors (stmt : statement) = |
---|
12 | match stmt with |
---|
13 | | St_tailcall_id _ |
---|
14 | | St_tailcall_ptr _ |
---|
15 | | St_return _ -> |
---|
16 | [] |
---|
17 | | St_skip l |
---|
18 | | St_clear_carry l |
---|
19 | | St_set_carry l |
---|
20 | | St_addr (_, _, _, l) |
---|
21 | | St_stackaddr (_, _, l) |
---|
22 | | St_cost (_, l) |
---|
23 | | St_ind_0 (_, l) |
---|
24 | | St_ind_inc (_, l) |
---|
25 | | St_move (_, _, l) |
---|
26 | | St_opaccs (_, _, _, _, _, l) |
---|
27 | | St_op1 (_, _, _, l) |
---|
28 | | St_op2 (_, _, _, _, l) |
---|
29 | | St_load (_, _, _, l) |
---|
30 | | St_store (_, _, _, l) |
---|
31 | | St_call_ptr (_, _, _, _, l) |
---|
32 | | St_call_id (_, _, _, l) -> |
---|
33 | [l] |
---|
34 | | St_cond (_, l1, l2) -> |
---|
35 | [l1 ; l2] |
---|
36 | |
---|
37 | let skip l = St_skip l |
---|
38 | |
---|
39 | let fill_succs stmt succs = match stmt, succs with |
---|
40 | | St_skip _, [lbl] -> St_skip lbl |
---|
41 | | St_cost (cost_lbl, _), [lbl] -> St_cost (cost_lbl, lbl) |
---|
42 | | St_ind_0 (i, _), [lbl] -> St_ind_0 (i, lbl) |
---|
43 | | St_ind_inc (i, _), [lbl] -> St_ind_inc (i, lbl) |
---|
44 | | St_addr (r1, r2, id, _), [lbl] -> St_addr (r1, r2, id, lbl) |
---|
45 | | St_stackaddr (r1, r2, _), [lbl] -> St_stackaddr (r1, r2, lbl) |
---|
46 | | St_move (r1, r2, _), [lbl] -> St_move (r1, r2, lbl) |
---|
47 | | St_opaccs (opaccs, dstr1, dstr2, srcr1, srcr2, _), [lbl] -> |
---|
48 | St_opaccs (opaccs, dstr1, dstr2, srcr1, srcr2, lbl) |
---|
49 | | St_op1 (op1, dstr, srcr, _), [lbl] -> St_op1 (op1, dstr, srcr, lbl) |
---|
50 | | St_op2 (op2, dstr, srcr1, srcr2, _), [lbl] -> |
---|
51 | St_op2 (op2, dstr, srcr1, srcr2, lbl) |
---|
52 | | St_clear_carry _, [lbl] -> St_clear_carry lbl |
---|
53 | | St_set_carry _, [lbl] -> St_set_carry lbl |
---|
54 | | St_load (dstrs, addr1, addr2, _), [lbl] -> |
---|
55 | St_load (dstrs, addr1, addr2, lbl) |
---|
56 | | St_store (addr1, addr2, srcrs, _), [lbl] -> |
---|
57 | St_store (addr1, addr2, srcrs, lbl) |
---|
58 | | St_call_id (f, args, retrs, _), [lbl] -> St_call_id (f, args, retrs, lbl) |
---|
59 | | St_call_ptr (f1, f2, args, retrs, _), [lbl] -> |
---|
60 | St_call_ptr (f1, f2, args, retrs, lbl) |
---|
61 | | St_cond (r, _, _), [lbl1; lbl2] -> St_cond (r, lbl1, lbl2) |
---|
62 | | St_tailcall_id (f, args), [] -> St_tailcall_id (f, args) |
---|
63 | | St_tailcall_ptr (f1, f2, args), [] -> St_tailcall_ptr (f1, f2, args) |
---|
64 | | St_return, [] -> St_return |
---|
65 | | _ -> invalid_arg "fill_succs: statement and successors do not match" |
---|