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.two-operand compiler.cfg.optimizer
11 compiler.cfg.instructions compiler.cfg.utilities
12 compiler.cfg.def-use compiler.cfg.rpo compiler.cfg.mr
13 compiler.cfg.representations.preferred compiler.cfg ;
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
48 : pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
50 M: ds-loc pprint* \ D pprint-loc ;
52 M: rs-loc pprint* \ R pprint-loc ;
54 : resolve-phis ( bb -- )
56 [ [ [ get ] dip ] assoc-map ] change-inputs drop
59 : test-bb ( insns n -- )
60 [ <basic-block> swap >>number swap >>instructions dup ] keep set
64 [ get ] bi@ 1vector >>successors drop ;
66 : edges ( from tos -- )
67 [ get ] [ [ get ] V{ } map-as ] bi* >>successors drop ;
75 : fake-representations ( cfg -- )
78 [ [ temp-vregs ] [ temp-vreg-reps ] bi zip ]
79 [ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ]
82 ] map concat >hashtable representations set ;