Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/visualization/cfgViewer.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/visualization/cfgViewer.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1173 - (view) (download)

1 : george 1087 functor CFGViewer
2 :     (structure CFG : CONTROL_FLOW_GRAPH
3 :     structure GraphViewer : GRAPH_VIEWER
4 :     structure Asm : INSTRUCTION_EMITTER where I = CFG.I)
5 :     : sig
6 :     val view : CFG.cfg -> unit
7 :     end =
8 :     struct
9 :     structure CFG = CFG
10 :     structure L = GraphLayout
11 :     structure FMT = FormatInstruction(Asm)
12 :     structure G = Graph
13 :    
14 :     val outline = MLRiscControl.getFlag "view-outline"
15 :    
16 :     fun view(cfg as G.GRAPH g) = let
17 :     val CFG.INFO{annotations, ...} = #graph_info g
18 :     val toString = FMT.toString (!annotations)
19 :     fun graph _ = []
20 : george 1173 val colorScale =
21 :     Array.fromList
22 :     ["#ccffff", "#99ffff", "#66ccff", "#54a9ff", "#ccff99",
23 :     "#ffff99", "#ffcc66", "#ff9966", "#cc6666", "#d14949",
24 :     "#d14949"]
25 : george 1087
26 : george 1173 fun weightRange([], min, max) = (min, max-min)
27 :     | weightRange((_,_,CFG.EDGE{w, ...})::rest, min, max) = let
28 :     val wt = !w
29 :     in
30 :     if wt > max then weightRange(rest, min, wt)
31 :     else if wt < min then weightRange(rest, wt, max)
32 :     else weightRange(rest, min, max)
33 :     end
34 : george 1087
35 : george 1173 val (loWt, range) = weightRange( #edges g (), ~1.0, ~1.0)
36 :    
37 : george 1087 val ENTRY = hd(#entries g ())
38 :     val EXIT = hd(#exits g ())
39 :    
40 : george 1173 val red = L.COLOR "#ff0000"
41 :     val yellow = L.COLOR "yellow"
42 :     val green = L.COLOR "green"
43 :    
44 : george 1087 fun edge(i,j,CFG.EDGE{w, ...}) =
45 : jhr 1125 let val label = L.LABEL(Real.toString (!w))
46 : george 1173 val color = let
47 :     val pos = floor (((!w - loWt) * 10.0 )/ range)
48 :     in
49 :     L.COLOR(Array.sub(colorScale, pos))
50 :     end
51 : george 1087 in [label, color] end
52 :    
53 :     fun title(blknum,ref freq) =
54 : jhr 1125 " "^Int.toString blknum^" ("^Real.toString freq^")"
55 : george 1087
56 :     fun ann(annotations) =
57 :     List.foldl(fn (a,l) => "/* "^Annotations.toString a^" */\n"^l) ""
58 :     (!annotations)
59 :    
60 :     fun node(_, CFG.BLOCK{kind, id, freq, insns, annotations, ...}) =
61 :     (case kind
62 :     of CFG.START =>
63 :     [L.LABEL("entry"^title(id,freq)^"\n"^ann(annotations))]
64 :     | CFG.STOP =>
65 :     [L.LABEL("exit"^title(id,freq))]
66 :     | _ =>
67 :     [L.LABEL(title(id,freq)^"\n"^
68 :     ann(annotations)^
69 :     (if !outline then "" else
70 :     List.foldl (fn (i,t) =>
71 :     let val text = toString i
72 :     in if text = "" then t else text^"\n"^t end
73 :     ) "" (!insns)))]
74 :     (*esac*))
75 :    
76 :     in
77 :     GraphViewer.view
78 :     (L.makeLayout{graph=graph, edge=edge, node=node} cfg)
79 :     end
80 :    
81 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0