1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel words sequences quotations namespaces io vectors
4 arrays hashtables classes.tuple accessors prettyprint
5 prettyprint.config assocs prettyprint.backend prettyprint.custom
6 prettyprint.sections parser compiler.tree.builder
7 compiler.tree.optimizer cpu.architecture compiler.cfg.builder
8 compiler.cfg.linearization compiler.cfg.registers
9 compiler.cfg.stack-frame compiler.cfg.linear-scan
10 compiler.cfg.optimizer compiler.cfg.instructions
11 compiler.cfg.utilities compiler.cfg.def-use compiler.cfg.rpo
12 compiler.cfg.mr compiler.cfg.representations.preferred
14 IN: compiler.cfg.debugger
16 GENERIC: test-cfg ( quot -- cfgs )
19 0 vreg-counter set-global
20 build-tree optimize-tree gensym build-cfg ;
23 0 vreg-counter set-global
24 [ build-tree optimize-tree ] keep build-cfg ;
26 : test-mr ( quot -- mrs )
35 tuple>array but-last [ pprint bl ] each nl ;
42 dup label>> pprint nl nl
43 instructions>> [ insn. ] each
47 : test-mr. ( quot -- )
51 : pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
53 M: ds-loc pprint* \ D pprint-loc ;
55 M: rs-loc pprint* \ R pprint-loc ;
57 : resolve-phis ( bb -- )
59 [ [ [ get ] dip ] assoc-map ] change-inputs drop
62 : test-bb ( insns n -- )
63 [ <basic-block> swap >>number swap >>instructions dup ] keep set
67 [ get ] bi@ 1vector >>successors drop ;
69 : edges ( from tos -- )
70 [ get ] [ [ get ] V{ } map-as ] bi* >>successors drop ;
78 : fake-representations ( cfg -- )
81 [ [ temp-vregs ] [ temp-vreg-reps ] bi zip ]
82 [ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ]
85 ] map concat >hashtable representations set ;