2009-05-25 20:16:58 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: kernel compiler.cfg.instructions compiler.cfg.rpo sequences
|
|
|
|
combinators.short-circuit accessors ;
|
|
|
|
IN: compiler.cfg.checker
|
|
|
|
|
|
|
|
ERROR: last-insn-not-a-jump insn ;
|
|
|
|
|
|
|
|
: check-basic-block ( bb -- )
|
|
|
|
peek dup {
|
|
|
|
[ ##branch? ]
|
|
|
|
[ ##conditional-branch? ]
|
|
|
|
[ ##compare-imm-branch? ]
|
|
|
|
[ ##return? ]
|
|
|
|
[ ##callback-return? ]
|
|
|
|
[ ##jump? ]
|
|
|
|
[ ##call? ]
|
|
|
|
[ ##dispatch-label? ]
|
|
|
|
} 1|| [ drop ] [ last-insn-not-a-jump ] if ;
|
|
|
|
|
2009-05-26 03:58:40 -04:00
|
|
|
: check-rpo ( rpo -- )
|
|
|
|
[ instructions>> check-basic-block ] each ;
|
|
|
|
|
2009-05-25 20:16:58 -04:00
|
|
|
: check-cfg ( cfg -- )
|
2009-05-26 20:31:19 -04:00
|
|
|
reverse-post-order check-rpo ;
|