]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/utilities/printCFG.ml
first version of the package
[pkg-cerco/acc.git] / src / utilities / printCFG.ml
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   in
19   let _, lines = visit (Label.Set.empty, []) entry in
20   String.concat "\n" (catenate (transposerev lines))
21