factor/library/compiler/optimizer/print-dataflow.factor

84 lines
2.2 KiB
Factor
Raw Normal View History

2005-09-09 00:17:19 -04:00
IN: optimizer
USING: generic hashtables inference io kernel kernel-internals
2006-05-15 01:01:47 -04:00
math namespaces prettyprint sequences styles vectors words ;
2005-07-27 01:46:06 -04:00
! A simple tool for turning dataflow IR into quotations, for
! debugging purposes.
GENERIC: node>quot ( node -- )
2005-08-02 06:32:48 -04:00
TUPLE: comment node text ;
2005-07-27 01:46:06 -04:00
2005-08-21 01:17:37 -04:00
M: comment pprint* ( ann -- )
2005-08-02 06:32:48 -04:00
"( " over comment-text " )" append3
2005-11-29 23:49:59 -05:00
swap comment-node presented associate text ;
2005-08-02 06:32:48 -04:00
: comment, ( ? node text -- )
2005-09-24 15:21:17 -04:00
rot [ <comment> , ] [ 2drop ] if ;
2005-07-27 01:46:06 -04:00
: values% ( prefix values -- )
[
swap %
dup value? [
value-literal unparse %
2006-01-21 16:16:49 -05:00
] [
"@" % #
2006-01-21 16:16:49 -05:00
] if
] each-with ;
2005-07-27 01:46:06 -04:00
: effect-str ( node -- str )
[
" " over node-in-d values%
" r: " over node-in-r values%
" --" %
" " over node-out-d values%
" r: " swap node-out-r values%
] "" make 1 swap tail ;
2005-07-27 01:46:06 -04:00
2005-09-04 17:07:59 -04:00
M: #shuffle node>quot ( ? node -- )
>r drop t r> dup effect-str "#shuffle: " swap append comment, ;
2005-07-27 01:46:06 -04:00
2006-04-17 17:17:34 -04:00
M: #push node>quot ( ? node -- ) nip >#push< % ;
2005-07-27 01:46:06 -04:00
DEFER: dataflow>quot
: #call>quot ( ? node -- )
dup node-param dup
2005-09-24 15:21:17 -04:00
[ , dup effect-str comment, ] [ 3drop ] if ;
2005-07-27 01:46:06 -04:00
M: #call node>quot ( ? node -- ) #call>quot ;
M: #call-label node>quot ( ? node -- ) #call>quot ;
2005-07-27 01:46:06 -04:00
2005-08-02 06:32:48 -04:00
M: #label node>quot ( ? node -- )
[ "#label: " over node-param word-name append comment, ] 2keep
2005-09-04 01:09:46 -04:00
node-child swap dataflow>quot , \ call , ;
2005-07-27 01:46:06 -04:00
2005-09-24 15:21:17 -04:00
M: #if node>quot ( ? node -- )
[ "#if" comment, ] 2keep
node-children [ swap dataflow>quot ] map-with % \ if , ;
2005-07-27 01:46:06 -04:00
2005-08-02 06:32:48 -04:00
M: #dispatch node>quot ( ? node -- )
[ "#dispatch" comment, ] 2keep
node-children [ swap dataflow>quot ] map-with , \ dispatch , ;
2005-07-27 01:46:06 -04:00
2005-09-10 00:55:46 -04:00
M: #return node>quot ( ? node -- )
dup node-param unparse "#return " swap append comment, ;
2005-07-27 01:46:06 -04:00
2006-05-02 06:05:58 -04:00
M: object node>quot ( ? node -- ) dup class word-name comment, ;
2005-09-18 01:37:28 -04:00
2005-08-02 06:32:48 -04:00
: (dataflow>quot) ( ? node -- )
dup [
2dup node>quot node-successor (dataflow>quot)
] [
2drop
2005-09-24 15:21:17 -04:00
] if ;
2005-07-27 01:46:06 -04:00
2005-08-02 06:32:48 -04:00
: dataflow>quot ( node ? -- quot )
2005-08-25 15:27:38 -04:00
[ swap (dataflow>quot) ] [ ] make ;
2005-07-27 01:46:06 -04:00
2005-08-02 06:32:48 -04:00
: dataflow. ( quot ? -- )
#! Print dataflow IR for a quotation. Flag indicates if
#! annotations should be printed or not.
2005-08-21 14:40:12 -04:00
>r dataflow optimize r> dataflow>quot . ;