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

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/flowgraph/cfg.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/flowgraph/cfg.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1103, Thu Feb 28 19:29:30 2002 UTC revision 1104, Thu Feb 28 19:56:53 2002 UTC
# Line 1  Line 1 
1  (*  (* cfg.sml
2     *
3     * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
4     *
5   * The control flow graph representation used for optimizations.   * The control flow graph representation used for optimizations.
6   *   *
7   * -- Allen   * -- Allen
8   *)   *)
9    
10  functor ControlFlowGraph  functor ControlFlowGraph
11     (structure I : INSTRUCTIONS     (structure I : INSTRUCTIONS
12      structure GraphImpl : GRAPH_IMPLEMENTATION      structure GraphImpl : GRAPH_IMPLEMENTATION
# Line 281  Line 285 
285      *  Pretty Printing and Viewing      *  Pretty Printing and Viewing
286      *      *
287      *========================================================================*)      *========================================================================*)
288     fun show_edge(EDGE{k,w,a,...}) =  
289         let val kind = case k of      structure F = Format
290                           JUMP      => ""  
291        fun show_edge (EDGE{k,w,a,...}) = let
292              val kind = (case k
293                     of JUMP        => "jump"
294                        |  FALLSTHRU => "fallsthru"                        |  FALLSTHRU => "fallsthru"
295                        |  BRANCH b => Bool.toString b                        |  BRANCH b => Bool.toString b
296                        |  SWITCH i => Int.toString i                        |  SWITCH i => Int.toString i
297                        |  ENTRY    => "entry"                        |  ENTRY    => "entry"
298                        |  EXIT     => "exit"                        |  EXIT     => "exit"
299                        |  FLOWSTO  => "flowsto"                        |  FLOWSTO  => "flowsto"
300             val weight = "(" ^ W.toString (!w) ^ ")"                  (* end case *))
301         in  kind ^ weight            in
302                F.format "%s(%d)" [F.STR kind, F.INT(!w)]
303         end         end
304    
305     fun getString f x =      fun getString f x = let
306     let val buffer = StringOutStream.mkStreamBuf()            val buffer = StringOutStream.mkStreamBuf()
307         val S      = StringOutStream.openStringOut buffer         val S      = StringOutStream.openStringOut buffer
308         val _      = AsmStream.withStream S f x         val _      = AsmStream.withStream S f x
309     in  StringOutStream.getString buffer end            in
310                StringOutStream.getString buffer
311              end
312    
313     fun show_block an block =      fun show_block an block = let
314     let val text = getString (emit an) block            val text = getString (emit an) block
315     in  foldr (fn (x,"") => x | (x,y) => x^" "^y) ""            in
316                foldr (fn (x,"") => x | (x,y) => x^" "^y) ""
317              (String.tokens (fn #" " => true | _ => false) text)              (String.tokens (fn #" " => true | _ => false) text)
318     end     end
319    
320        fun dump (outS, title, cfg as G.GRAPH g) = let
321              fun pr str = TextIO.output(outS, str)
322              fun prList [] = ()
323                | prList [i] = pr i
324                | prList (h::t) = (pr (h ^ ", "); prList t)
325              val annotations = !(annotations cfg)
326              val Asm.S.STREAM{emit,pseudoOp,defineLabel,annotation,...} =
327                    AsmStream.withStream outS Asm.makeStream annotations
328              fun showFreq (ref w) = F.format "[%s]" [F.STR(W.toString w)]
329              fun showEdge (blknum,e) =
330                    F.format "%d:%s" [F.INT blknum, F.STR(show_edge e)]
331              fun showSucc (_, x, e) = showEdge(x,e)
332              fun showPred (x, _, e) = showEdge(x,e)
333              fun showSuccs b = (
334                    pr "\tsucc:     ";
335                    prList (map showSucc (#out_edges g b));
336                    pr "\n")
337              fun showPreds b = (
338                    pr "\tpred:     ";
339                    prList (map showPred (#in_edges g b));
340                    pr "\n")
341              fun printBlock (_, BLOCK{kind=START, id, freq, ...}) = (
342                    pr (F.format "ENTRY %d %s\n" [F.INT id, F.STR(showFreq freq)]);
343                    showSuccs id)
344                | printBlock (_, BLOCK{kind=STOP, id, freq, ...}) = (
345                    pr (F.format "EXIT %d %s\n" [F.INT id, F.STR(showFreq freq)]);
346                    showPreds id)
347                | printBlock (
348                    _, BLOCK{id, align, freq, insns, annotations, labels, ...}
349                  ) = (
350                   pr (F.format "BLOCK %d %s\n" [F.INT id, F.STR(showFreq freq)]);
351                   case !align of NONE => () | SOME p => (pr (P.toString p ^ "\n"));
352                   app annotation (!annotations);
353                   app defineLabel (!labels);
354                   showSuccs id;
355                   showPreds id;
356                   List.app emit (List.rev (!insns)))
357              fun printData () = let
358                    val INFO{data, ...} = #graph_info g
359                    in
360                      List.app (pr o P.toString) (rev(!data))
361                    end
362              in
363                pr(F.format "[ %s ]\n" [F.STR title]);
364                List.app annotation annotations;
365                (* printBlock entry; *)
366                AsmStream.withStream outS (#forall_nodes g) printBlock;
367                (* printBlock exit; *)
368                AsmStream.withStream outS printData ();
369                TextIO.flushOut outS
370              end
371    
372  end  end
373    

Legend:
Removed from v.1103  
changed lines
  Added in v.1104

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