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 1087 - (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 W = CFG.W
11 :     structure L = GraphLayout
12 :     structure FMT = FormatInstruction(Asm)
13 :     structure G = Graph
14 :    
15 :     val outline = MLRiscControl.getFlag "view-outline"
16 :    
17 :     fun view(cfg as G.GRAPH g) = let
18 :     val CFG.INFO{annotations, ...} = #graph_info g
19 :     val toString = FMT.toString (!annotations)
20 :     fun graph _ = []
21 :    
22 :     val red = L.COLOR "red"
23 :     val yellow = L.COLOR "yellow"
24 :     val green = L.COLOR "green"
25 :    
26 :     val ENTRY = hd(#entries g ())
27 :     val EXIT = hd(#exits g ())
28 :    
29 :     fun edge(i,j,CFG.EDGE{w, ...}) =
30 :     let val label = L.LABEL(W.toString (!w))
31 :     val color =
32 :     if i = ENTRY orelse j = EXIT then green (* special edge *)
33 :     else if i+1 = j then yellow (* fallsthru *)
34 :     else red
35 :     in [label, color] end
36 :    
37 :     fun title(blknum,ref freq) =
38 :     " "^Int.toString blknum^" ("^W.toString freq^")"
39 :    
40 :     fun ann(annotations) =
41 :     List.foldl(fn (a,l) => "/* "^Annotations.toString a^" */\n"^l) ""
42 :     (!annotations)
43 :    
44 :     fun node(_, CFG.BLOCK{kind, id, freq, insns, annotations, ...}) =
45 :     (case kind
46 :     of CFG.START =>
47 :     [L.LABEL("entry"^title(id,freq)^"\n"^ann(annotations))]
48 :     | CFG.STOP =>
49 :     [L.LABEL("exit"^title(id,freq))]
50 :     | _ =>
51 :     [L.LABEL(title(id,freq)^"\n"^
52 :     ann(annotations)^
53 :     (if !outline then "" else
54 :     List.foldl (fn (i,t) =>
55 :     let val text = toString i
56 :     in if text = "" then t else text^"\n"^t end
57 :     ) "" (!insns)))]
58 :     (*esac*))
59 :    
60 :     in
61 :     GraphViewer.view
62 :     (L.makeLayout{graph=graph, edge=edge, node=node} cfg)
63 :     end
64 :    
65 :     end

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