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 924 - (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 :     structure CFG : CONTROL_FLOW_GRAPH
8 :     structure Asm : INSTRUCTION_EMITTER
9 :     where I = CFG.I and P = CFG.P
10 :    
11 :     val printCFG : TextIO.outstream -> string -> CFG.cfg -> unit
12 :     end
13 :    
14 :    
15 :     functor PrintFlowgraph
16 :     (structure CFG : CONTROL_FLOW_GRAPH
17 :     structure Asm : INSTRUCTION_EMITTER
18 :     where P=CFG.P and I=CFG.I
19 :     ) : PRINT_FLOWGRAPH =
20 :     struct
21 :     structure Asm = Asm
22 :     structure CFG = CFG
23 :     structure C = CFG.I.C
24 :     structure W = CFG.W
25 :    
26 :     val i2s = Int.toString
27 :    
28 :     fun printList stream list = let
29 :     fun pr str = TextIO.output(stream, str)
30 :     fun iter [] = ()
31 :     | iter [i] = pr i
32 :     | iter (h::t) = (pr (h ^ ", "); iter t)
33 :     in iter list
34 :     end
35 :    
36 :     fun printCFG stream title (Cfg as Graph.GRAPH cfg) =
37 :     let fun pr str = TextIO.output(stream, str)
38 :     val prList = printList stream
39 :     val annotations = !(CFG.annotations Cfg)
40 :     val Asm.S.STREAM{emit,pseudoOp,defineLabel,annotation,...} =
41 :     AsmStream.withStream stream Asm.makeStream annotations
42 :    
43 :     fun showFreq(ref w) = "["^W.toString w^"]"
44 :     fun showEdge(blknum,e) = i2s blknum^":"^CFG.show_edge e
45 :     fun showSucc(_, x, e) = showEdge(x,e)
46 :     fun showPred(x, _, e) = showEdge(x,e)
47 :     fun showSuccs b =
48 :     (pr "\tsucc: ";
49 :     prList (map showSucc (#out_edges cfg b));
50 :     pr "\n")
51 :     fun showPreds b =
52 :     (pr "\tpred: ";
53 :     prList (map showPred (#in_edges cfg b));
54 :     pr "\n")
55 :    
56 :     fun printBlock(_, CFG.BLOCK{kind=CFG.START, id, freq, ...}) =
57 :     (pr ("ENTRY " ^ i2s id ^ showFreq freq^"\n");
58 :     showSuccs id)
59 :     | printBlock(_, CFG.BLOCK{kind=CFG.STOP, id, freq, ...}) =
60 :     (pr ("EXIT " ^ i2s id ^ showFreq freq ^"\n");
61 :     showPreds id)
62 :     | printBlock(_, CFG.BLOCK{id, freq, insns, annotations, data,
63 :     labels, ...}) =
64 :     (pr ("BLOCK " ^ i2s id ^ showFreq freq ^ "\n");
65 :     app annotation (!annotations);
66 :     app (fn CFG.PSEUDO pOp => pseudoOp pOp
67 :     | CFG.LABEL l => defineLabel l
68 :     ) (!data);
69 :     app defineLabel (!labels);
70 :     (*pr ("\tlive in: " ^ CellsBasis.CellSet.toString (!liveIn) ^ "\n");
71 :     pr ("\tlive out: " ^ CellsBasis.CellSet.toString (!liveOut) ^ "\n");*)
72 :     showSuccs id;
73 :     showPreds id;
74 :     app emit (rev (!insns)))
75 :     in
76 :     pr("[ "^ title ^" ]\n");
77 :     app annotation annotations;
78 :     (* printBlock entry; *)
79 :     AsmStream.withStream stream (#forall_nodes cfg) printBlock;
80 :     (* printBlock exit; *)
81 :     TextIO.flushOut stream
82 :     end
83 :     end
84 :    

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