2009-05-25 20:16:58 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-05-28 03:49:51 -04:00
|
|
|
USING: kernel compiler.cfg.instructions compiler.cfg.rpo
|
|
|
|
compiler.cfg.def-use compiler.cfg.linearization compiler.cfg.liveness
|
|
|
|
combinators.short-circuit accessors math sequences sets assocs ;
|
2009-05-25 20:16:58 -04:00
|
|
|
IN: compiler.cfg.checker
|
|
|
|
|
|
|
|
ERROR: last-insn-not-a-jump insn ;
|
|
|
|
|
2009-05-27 19:58:14 -04:00
|
|
|
: check-last-instruction ( bb -- )
|
2009-06-01 10:34:28 -04:00
|
|
|
last dup {
|
2009-05-25 20:16:58 -04:00
|
|
|
[ ##branch? ]
|
2009-05-29 02:39:14 -04:00
|
|
|
[ ##dispatch? ]
|
2009-05-25 20:16:58 -04:00
|
|
|
[ ##conditional-branch? ]
|
|
|
|
[ ##compare-imm-branch? ]
|
|
|
|
[ ##return? ]
|
|
|
|
[ ##callback-return? ]
|
|
|
|
[ ##jump? ]
|
2009-06-05 18:32:12 -04:00
|
|
|
[ ##fixnum-add-tail? ]
|
|
|
|
[ ##fixnum-sub-tail? ]
|
|
|
|
[ ##fixnum-mul-tail? ]
|
2009-07-01 00:17:33 -04:00
|
|
|
[ ##no-tco? ]
|
2009-05-25 20:16:58 -04:00
|
|
|
} 1|| [ drop ] [ last-insn-not-a-jump ] if ;
|
|
|
|
|
2009-05-27 19:58:14 -04:00
|
|
|
ERROR: bad-loop-entry ;
|
|
|
|
|
|
|
|
: check-loop-entry ( bb -- )
|
|
|
|
dup length 2 >= [
|
|
|
|
2 head* [ ##loop-entry? ] any?
|
|
|
|
[ bad-loop-entry ] when
|
|
|
|
] [ drop ] if ;
|
|
|
|
|
2009-05-28 03:49:51 -04:00
|
|
|
ERROR: bad-successors ;
|
|
|
|
|
|
|
|
: check-successors ( bb -- )
|
|
|
|
dup successors>> [ predecessors>> memq? ] with all?
|
|
|
|
[ bad-successors ] unless ;
|
|
|
|
|
2009-05-27 19:58:14 -04:00
|
|
|
: check-basic-block ( bb -- )
|
2009-05-28 03:49:51 -04:00
|
|
|
[ instructions>> check-last-instruction ]
|
|
|
|
[ instructions>> check-loop-entry ]
|
|
|
|
[ check-successors ]
|
|
|
|
tri ;
|
|
|
|
|
|
|
|
ERROR: bad-live-in ;
|
2009-05-27 19:58:14 -04:00
|
|
|
|
|
|
|
ERROR: undefined-values uses defs ;
|
|
|
|
|
|
|
|
: check-mr ( mr -- )
|
|
|
|
! Check that every used register has a definition
|
|
|
|
instructions>>
|
|
|
|
[ [ uses-vregs ] map concat ]
|
2009-05-29 14:11:34 -04:00
|
|
|
[ [ [ defs-vregs ] [ temp-vregs ] bi append ] map concat ] bi
|
2009-05-27 19:58:14 -04:00
|
|
|
2dup subset? [ 2drop ] [ undefined-values ] if ;
|
|
|
|
|
2009-05-25 20:16:58 -04:00
|
|
|
: check-cfg ( cfg -- )
|
2009-05-29 14:11:34 -04:00
|
|
|
compute-liveness
|
|
|
|
[ entry>> live-in assoc-empty? [ bad-live-in ] unless ]
|
|
|
|
[ [ check-basic-block ] each-basic-block ]
|
2009-05-31 13:20:46 -04:00
|
|
|
[ flatten-cfg check-mr ]
|
2009-05-29 14:11:34 -04:00
|
|
|
tri ;
|