compiler.cfg.graphviz: A utility for rendering CFGs with graphviz

Slava Pestov 2009-07-28 06:41:29 -05:00
parent 3550880850
commit d914e9cc4f
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license
USING: accessors compiler.cfg.rpo images.viewer io
io.encodings.ascii io.files io.files.unique io.launcher kernel
math.parser sequences ;
IN: compiler.cfg.graphviz
: cfg>dot ( cfg -- )
"digraph CFG {" print
[
[ number>> ] [ successors>> ] bi [
number>> [ number>string ] bi@ " -> " glue write ";" print
] with each
] each-basic-block
"}" print ;
: render-cfg ( cfg -- )
"cfg" "dot" make-unique-file
[ ascii [ cfg>dot ] with-file-writer ]
[ { "dot" "-Tpng" "-O" } swap suffix try-process ]
[ ".png" append { "open" } swap suffix try-process ]
tri ;