Line | |
---|
1 | (* Pasted from Pottier's PP compiler *) |
---|
2 | |
---|
3 | open PrintPottier |
---|
4 | |
---|
5 | let print_graph instruction successors () (graph, entry) = |
---|
6 | |
---|
7 | (* Print instructions in depth-first order; this is a |
---|
8 | rather natural and readable order. *) |
---|
9 | |
---|
10 | let rec visit (visited, lines) l = |
---|
11 | if Label.Set.mem l visited then |
---|
12 | visited, lines |
---|
13 | else |
---|
14 | let visited = Label.Set.add l visited in |
---|
15 | let i = Label.Map.find l graph in |
---|
16 | let lines = instruction l i :: lines in |
---|
17 | List.fold_left visit (visited, lines) (successors i) |
---|
18 | (* |
---|
19 | try |
---|
20 | let i = Label.Map.find l graph in |
---|
21 | let lines = instruction l i :: lines in |
---|
22 | List.fold_left visit (visited, lines) (successors i) |
---|
23 | with Not_found -> |
---|
24 | visited, lines |
---|
25 | *) |
---|
26 | in |
---|
27 | |
---|
28 | let _, lines = visit (Label.Set.empty, []) entry in |
---|
29 | String.concat "\n" (catenate (transposerev lines)) |
---|
30 | |
---|
Note: See
TracBrowser
for help on using the repository browser.