1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel compiler.cfg.instructions compiler.cfg.rpo
4 compiler.cfg.def-use compiler.cfg.linearization
5 combinators.short-circuit accessors math sequences sets assocs ;
6 IN: compiler.cfg.checker
8 ERROR: last-insn-not-a-jump insn ;
10 : check-last-instruction ( bb -- )
14 [ ##conditional-branch? ]
15 [ ##compare-imm-branch? ]
17 [ ##callback-return? ]
23 } 1|| [ drop ] [ last-insn-not-a-jump ] if ;
25 ERROR: bad-loop-entry ;
27 : check-loop-entry ( bb -- )
29 2 head* [ ##loop-entry? ] any?
30 [ bad-loop-entry ] when
33 ERROR: bad-successors ;
35 : check-successors ( bb -- )
36 dup successors>> [ predecessors>> memq? ] with all?
37 [ bad-successors ] unless ;
39 : check-basic-block ( bb -- )
40 [ instructions>> check-last-instruction ]
41 [ instructions>> check-loop-entry ]
47 ERROR: undefined-values uses defs ;
50 ! Check that every used register has a definition
52 [ [ uses-vregs ] map concat ]
53 [ [ [ defs-vregs ] [ temp-vregs ] bi append ] map concat ] bi
54 2dup subset? [ 2drop ] [ undefined-values ] if ;
56 : check-cfg ( cfg -- )
57 [ [ check-basic-block ] each-basic-block ]
58 [ flatten-cfg check-mr ]