Debian Codegraph @

lib/mlrisc-lib/MLRISC/visualization/dot.sml

raw
1 (*
2 * This communicates with the dot tool
3 *
4 * -- Allen
5 *)
6
7 structure Dot : GRAPH_DISPLAY =
8 struct
9
10 structure L = GraphLayout
11 structure G = Graph
12
13 fun suffix() = ".dot"
14 fun program() = "dotty"
15
16 fun visualize out (G.GRAPH G) =
17 let val spaces = " ";
18 fun int n = out (Int.toString n)
19 fun tab t = out(String.substring(spaces,0,t)) handle _ => out spaces
20 fun semi() = out ";"
21 fun name n = if n < 0 then (out "XX"; int(~n))
22 else (out "X"; int n)
23 fun attribs t a = (out "[ shape=box"; doAttribs t "," a; out "]")
24
25 and doAttrib t comma (L.LABEL "") = false
26 | doAttrib t comma (L.LABEL l) = (out comma; tab t; label l; true)
27 | doAttrib t comma (L.COLOR c) =
28 (out comma; tab t; out "color=\""; out c; out "\""; true)
29 | doAttrib t comma _ = false
30
31 and doAttribs t comma [] = ()
32 | doAttribs t comma (l::ls) =
33 doAttribs t (if doAttrib t comma l then ",\n" else comma) ls
34
35 and label l = (out "label=\""; out(String.toString l); out "\"\n")
36
37 fun doNode t (n,a) = (tab t; name n; attribs t a; semi())
38
39 fun doEdge t (i,j,a) =
40 (tab t; name i; out "-> "; name j; attribs t a; semi())
41
42 in out("digraph " ^ #name G ^ " {\n");
43 #forall_nodes G (doNode 2);
44 #forall_edges G (doEdge 2);
45 out "}\n"
46 end
47
48 end