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/flowgraph/printFlowgraph.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/flowgraph/printFlowgraph.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 984 - (view) (download)

1 : jhr 924 (* printFlowgraph.sml -- print flowgraph of target machine instructions.
2 :     *
3 :     * Copyright (c) 1997 Bell Laboratories.
4 :     *)
5 :     signature PRINT_FLOWGRAPH =
6 :     sig
7 : george 984 structure Asm : INSTRUCTION_EMITTER
8 : jhr 924 structure CFG : CONTROL_FLOW_GRAPH
9 : george 984 where I = Asm.I
10 :     and P = Asm.S.P
11 : jhr 924
12 :     val printCFG : TextIO.outstream -> string -> CFG.cfg -> unit
13 :     end
14 :    
15 :    
16 :     functor PrintFlowgraph
17 : george 984 (structure Asm : INSTRUCTION_EMITTER
18 :     structure CFG : CONTROL_FLOW_GRAPH
19 :     where I = Asm.I
20 :     and P = Asm.S.P
21 : jhr 924 ) : PRINT_FLOWGRAPH =
22 :     struct
23 :     structure Asm = Asm
24 :     structure CFG = CFG
25 :     structure C = CFG.I.C
26 :     structure W = CFG.W
27 : george 984 structure Fmt = Format
28 : jhr 924
29 :     val i2s = Int.toString
30 :    
31 :     fun printList stream list = let
32 :     fun pr str = TextIO.output(stream, str)
33 :     fun iter [] = ()
34 :     | iter [i] = pr i
35 :     | iter (h::t) = (pr (h ^ ", "); iter t)
36 :     in iter list
37 :     end
38 :    
39 :     fun printCFG stream title (Cfg as Graph.GRAPH cfg) =
40 :     let fun pr str = TextIO.output(stream, str)
41 :     val prList = printList stream
42 :     val annotations = !(CFG.annotations Cfg)
43 :     val Asm.S.STREAM{emit,pseudoOp,defineLabel,annotation,...} =
44 :     AsmStream.withStream stream Asm.makeStream annotations
45 :    
46 : george 984 fun showFreq(ref w) = Fmt.format "[%s]" [Fmt.STR(W.toString w)]
47 :     fun showEdge(blknum,e) =
48 :     Fmt.format "%d:%s" [Fmt.INT blknum, Fmt.STR(CFG.show_edge e)]
49 : jhr 924 fun showSucc(_, x, e) = showEdge(x,e)
50 : george 984 fun showPred(x, _, e) = showEdge(x,e)
51 : jhr 924 fun showSuccs b =
52 :     (pr "\tsucc: ";
53 :     prList (map showSucc (#out_edges cfg b));
54 :     pr "\n")
55 :     fun showPreds b =
56 :     (pr "\tpred: ";
57 :     prList (map showPred (#in_edges cfg b));
58 :     pr "\n")
59 :    
60 :     fun printBlock(_, CFG.BLOCK{kind=CFG.START, id, freq, ...}) =
61 : george 984 (pr (Fmt.format "ENTRY %d %s\n" [Fmt.INT id, Fmt.STR(showFreq freq)]);
62 : jhr 924 showSuccs id)
63 :     | printBlock(_, CFG.BLOCK{kind=CFG.STOP, id, freq, ...}) =
64 : george 984 (pr (Fmt.format "EXIT %d %s\n" [Fmt.INT id, Fmt.STR(showFreq freq)]);
65 : jhr 924 showPreds id)
66 : george 984 | printBlock(_, CFG.BLOCK{id, align, freq, insns, annotations,
67 : jhr 924 labels, ...}) =
68 : george 984 (pr (Fmt.format "BLOCK %d %s\n" [Fmt.INT id, Fmt.STR(showFreq freq)]);
69 :     case !align of NONE => () | SOME p => (pr (CFG.P.toString p ^ "\n"));
70 : jhr 924 app annotation (!annotations);
71 :     app defineLabel (!labels);
72 : george 984 (*
73 :     pr ("\tlive in: " ^ CellsBasis.CellSet.toString (!liveIn) ^ "\n");
74 :     pr ("\tlive out: " ^ CellsBasis.CellSet.toString (!liveOut) ^ "\n");
75 :     *)
76 : jhr 924 showSuccs id;
77 :     showPreds id;
78 :     app emit (rev (!insns)))
79 : george 984
80 :     fun printData() = let
81 :     val CFG.INFO{data, ...} = #graph_info cfg
82 :     in List.app (pr o CFG.P.toString) (rev(!data))
83 :     end
84 : jhr 924 in
85 : george 984 pr(Fmt.format "[ %s ]\n" [Fmt.STR title]);
86 : jhr 924 app annotation annotations;
87 :     (* printBlock entry; *)
88 :     AsmStream.withStream stream (#forall_nodes cfg) printBlock;
89 :     (* printBlock exit; *)
90 : george 984 AsmStream.withStream stream printData ();
91 : jhr 924 TextIO.flushOut stream
92 :     end
93 :     end
94 :    

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