2009-06-26 18:29:55 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-09-11 03:05:22 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-06-26 18:29:55 -04:00
|
|
|
USING: kernel words sequences quotations namespaces io vectors
|
2009-08-26 00:44:01 -04:00
|
|
|
arrays hashtables classes.tuple accessors prettyprint
|
|
|
|
prettyprint.config assocs prettyprint.backend prettyprint.custom
|
|
|
|
prettyprint.sections parser compiler.tree.builder
|
|
|
|
compiler.tree.optimizer cpu.architecture compiler.cfg.builder
|
|
|
|
compiler.cfg.linearization compiler.cfg.registers
|
|
|
|
compiler.cfg.stack-frame compiler.cfg.linear-scan
|
2009-09-27 21:34:20 -04:00
|
|
|
compiler.cfg.optimizer compiler.cfg.instructions
|
|
|
|
compiler.cfg.utilities compiler.cfg.def-use compiler.cfg.rpo
|
|
|
|
compiler.cfg.mr compiler.cfg.representations.preferred
|
|
|
|
compiler.cfg ;
|
2008-09-11 03:05:22 -04:00
|
|
|
IN: compiler.cfg.debugger
|
|
|
|
|
|
|
|
GENERIC: test-cfg ( quot -- cfgs )
|
|
|
|
|
|
|
|
M: callable test-cfg
|
2009-07-27 23:28:13 -04:00
|
|
|
0 vreg-counter set-global
|
2008-09-17 01:46:38 -04:00
|
|
|
build-tree optimize-tree gensym build-cfg ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
|
|
|
M: word test-cfg
|
2009-07-27 23:28:13 -04:00
|
|
|
0 vreg-counter set-global
|
2009-04-22 00:02:00 -04:00
|
|
|
[ build-tree optimize-tree ] keep build-cfg ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
2008-10-07 21:00:38 -04:00
|
|
|
: test-mr ( quot -- mrs )
|
2008-10-20 02:56:28 -04:00
|
|
|
test-cfg [
|
2009-08-08 21:02:56 -04:00
|
|
|
[
|
|
|
|
optimize-cfg
|
|
|
|
build-mr
|
|
|
|
] with-cfg
|
2008-10-20 02:56:28 -04:00
|
|
|
] map ;
|
|
|
|
|
|
|
|
: insn. ( insn -- )
|
2009-07-10 04:05:45 -04:00
|
|
|
tuple>array but-last [ pprint bl ] each nl ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
|
|
|
: mr. ( mrs -- )
|
|
|
|
[
|
|
|
|
"=== word: " write
|
|
|
|
dup word>> pprint
|
|
|
|
", label: " write
|
|
|
|
dup label>> pprint nl nl
|
2008-10-20 02:56:28 -04:00
|
|
|
instructions>> [ insn. ] each
|
2008-09-11 03:05:22 -04:00
|
|
|
nl
|
|
|
|
] each ;
|
2008-12-08 15:58:00 -05:00
|
|
|
|
2009-09-30 12:34:19 -04:00
|
|
|
: test-mr. ( quot -- )
|
|
|
|
test-mr mr. ; inline
|
|
|
|
|
2008-12-08 15:58:00 -05:00
|
|
|
! Prettyprinting
|
|
|
|
: pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
|
|
|
|
|
|
|
|
M: ds-loc pprint* \ D pprint-loc ;
|
|
|
|
|
|
|
|
M: rs-loc pprint* \ R pprint-loc ;
|
2009-06-26 18:29:55 -04:00
|
|
|
|
2009-08-02 04:49:25 -04:00
|
|
|
: resolve-phis ( bb -- )
|
2009-08-02 07:16:58 -04:00
|
|
|
[
|
2009-08-02 04:49:25 -04:00
|
|
|
[ [ [ get ] dip ] assoc-map ] change-inputs drop
|
2009-08-02 07:16:58 -04:00
|
|
|
] each-phi ;
|
2009-08-02 04:49:25 -04:00
|
|
|
|
2009-06-26 18:29:55 -04:00
|
|
|
: test-bb ( insns n -- )
|
2009-08-02 04:49:25 -04:00
|
|
|
[ <basic-block> swap >>number swap >>instructions dup ] keep set
|
|
|
|
resolve-phis ;
|
|
|
|
|
|
|
|
: edge ( from to -- )
|
|
|
|
[ get ] bi@ 1vector >>successors drop ;
|
|
|
|
|
|
|
|
: edges ( from tos -- )
|
|
|
|
[ get ] [ [ get ] V{ } map-as ] bi* >>successors drop ;
|
2009-06-26 18:29:55 -04:00
|
|
|
|
|
|
|
: test-diamond ( -- )
|
2009-08-02 04:49:25 -04:00
|
|
|
0 1 edge
|
|
|
|
1 { 2 3 } edges
|
|
|
|
2 4 edge
|
2009-08-08 05:02:18 -04:00
|
|
|
3 4 edge ;
|
|
|
|
|
|
|
|
: fake-representations ( cfg -- )
|
|
|
|
post-order [
|
2009-08-26 00:44:01 -04:00
|
|
|
instructions>> [
|
|
|
|
[ [ temp-vregs ] [ temp-vreg-reps ] bi zip ]
|
|
|
|
[ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ]
|
|
|
|
bi [ suffix ] when*
|
|
|
|
] map concat
|
2009-09-30 12:34:19 -04:00
|
|
|
] map concat >hashtable representations set ;
|