2010-01-06 23:39:22 -05:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
2009-06-02 19:23:47 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-05-16 03:43:02 -04:00
|
|
|
USING: namespaces accessors math math.order assocs kernel sequences
|
2010-05-02 18:48:41 -04:00
|
|
|
combinators classes words cpu.architecture layouts compiler.cfg
|
|
|
|
compiler.cfg.rpo compiler.cfg.instructions
|
|
|
|
compiler.cfg.registers compiler.cfg.stack-frame ;
|
2009-06-02 19:23:47 -04:00
|
|
|
IN: compiler.cfg.build-stack-frame
|
|
|
|
|
|
|
|
SYMBOL: frame-required?
|
|
|
|
|
|
|
|
GENERIC: compute-stack-frame* ( insn -- )
|
|
|
|
|
|
|
|
: request-stack-frame ( stack-frame -- )
|
2009-07-19 21:12:04 -04:00
|
|
|
frame-required? on
|
2009-06-02 19:23:47 -04:00
|
|
|
stack-frame [ max-stack-frame ] change ;
|
|
|
|
|
2010-05-09 21:36:52 -04:00
|
|
|
M: ##stack-frame compute-stack-frame*
|
2009-06-02 19:23:47 -04:00
|
|
|
stack-frame>> request-stack-frame ;
|
|
|
|
|
2010-04-27 10:51:00 -04:00
|
|
|
M: ##call-gc compute-stack-frame*
|
|
|
|
drop
|
2009-06-02 19:23:47 -04:00
|
|
|
frame-required? on
|
2010-04-27 10:51:00 -04:00
|
|
|
stack-frame new t >>calls-vm? request-stack-frame ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2010-05-16 03:43:02 -04:00
|
|
|
M: ##call compute-stack-frame* drop frame-required? on ;
|
|
|
|
|
|
|
|
M: ##alien-callback compute-stack-frame* drop frame-required? on ;
|
|
|
|
|
2009-06-02 19:23:47 -04:00
|
|
|
M: insn compute-stack-frame*
|
2010-05-02 18:48:41 -04:00
|
|
|
class "frame-required?" word-prop
|
|
|
|
[ frame-required? on ] when ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2010-05-02 18:48:41 -04:00
|
|
|
: initial-stack-frame ( -- stack-frame )
|
|
|
|
stack-frame new cfg get spill-area-size>> >>spill-area-size ;
|
2009-06-02 19:23:47 -04:00
|
|
|
|
2010-05-16 03:43:02 -04:00
|
|
|
: compute-stack-frame ( cfg -- )
|
2010-05-02 18:48:41 -04:00
|
|
|
initial-stack-frame stack-frame set
|
2010-05-16 03:43:02 -04:00
|
|
|
[ spill-area-size>> 0 > frame-required? set ]
|
|
|
|
[ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ] bi
|
2009-06-02 19:23:47 -04:00
|
|
|
stack-frame get dup stack-frame-size >>total-size drop ;
|
|
|
|
|
2010-05-02 18:48:41 -04:00
|
|
|
: build-stack-frame ( cfg -- cfg )
|
2009-06-02 19:23:47 -04:00
|
|
|
[
|
2010-05-02 18:48:41 -04:00
|
|
|
[ compute-stack-frame ]
|
2009-06-02 19:23:47 -04:00
|
|
|
[
|
2010-05-02 18:48:41 -04:00
|
|
|
frame-required? get stack-frame get f ?
|
|
|
|
>>stack-frame
|
|
|
|
] bi
|
2009-06-02 19:23:47 -04:00
|
|
|
] with-scope ;
|