compiler.cfg.graphviz: tweak code & output a little

db4
Alex Vondrak 2011-06-04 12:38:42 -07:00 committed by John Benediktsson
parent d6849da7ec
commit 51b3b1fd87
1 changed files with 13 additions and 26 deletions

View File

@ -42,41 +42,28 @@ IN: compiler.cfg.graphviz
[ number>> ] bi@ -> [ number>> ] bi@ ->
] with each ; ] with each ;
SYMBOL: linearize? : cfgviz ( cfg -- graph )
linearize? off
: ?linearize ( graph cfg -- graph' )
linearize? get [
<anon>
edge[ "invis" =style ];
swap linearization-order [ number>> ] map ~->
add
] [ drop ] if ;
: cfgviz ( cfg filename -- cfg )
over
<digraph> <digraph>
graph[ "t" =labelloc ]; graph[ "t" =labelloc ];
node[ "box" =shape "Courier" =fontname 10 =fontsize ]; node[ "box" =shape "Courier" =fontname 10 =fontsize ];
swap swap [
[ ?linearize ] [ add-cfg-vertex ] [ add-cfg-edges ] bi
[ [ add-cfg-vertex ] each-basic-block ] ] each-basic-block ;
[ [ add-cfg-edges ] each-basic-block ]
tri
swap png ;
: perform-pass ( cfg pass -- cfg' ) : perform-pass ( cfg pass pass# -- cfg' )
def>> call( cfg -- cfg' ) ; drop def>> call( cfg -- cfg' ) ;
: pass-file ( pass pass# -- path ) : draw-cfg ( cfg pass pass# -- cfg )
[ name>> ] [ number>string "-" append ] bi* prepend ; [ dup cfgviz ]
[ name>> "After " prepend =label ]
[ number>string png ]
tri* ;
: watch-pass ( cfg pass pass# -- cfg' ) : watch-pass ( cfg pass pass# -- cfg' )
[ drop perform-pass ] 2keep [ perform-pass ] 2keep draw-cfg ;
pass-file cfgviz ;
: begin-watching-passes ( cfg -- cfg ) : begin-watching-passes ( cfg -- cfg )
"0-build-cfg" cfgviz ; \ build-cfg 0 draw-cfg ;
: watch-passes ( cfg -- cfg' ) : watch-passes ( cfg -- cfg' )
\ optimize-cfg def>> [ 1 + watch-pass ] each-index ; \ optimize-cfg def>> [ 1 + watch-pass ] each-index ;