factor/basis/compiler/cfg/stack-frame/stack-frame.factor

66 lines
1.7 KiB
Factor
Raw Normal View History

! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces accessors math.order assocs kernel sequences
make compiler.cfg.instructions compiler.cfg.instructions.syntax
compiler.cfg.registers ;
IN: compiler.cfg.stack-frame
SYMBOL: frame-required?
SYMBOL: spill-counts
: init-stack-frame-builder ( -- )
frame-required? off
2008-10-07 17:13:29 -04:00
T{ stack-frame } clone stack-frame set ;
GENERIC: compute-stack-frame* ( insn -- )
2008-10-07 17:13:29 -04:00
: max-stack-frame ( frame1 frame2 -- frame3 )
{
[ [ size>> ] bi@ max ]
[ [ params>> ] bi@ max ]
[ [ return>> ] bi@ max ]
[ [ total-size>> ] bi@ max ]
} cleave
stack-frame boa ;
2008-10-07 17:13:29 -04:00
M: ##stack-frame compute-stack-frame*
frame-required? on
2008-10-07 17:13:29 -04:00
stack-frame>> stack-frame [ max-stack-frame ] change ;
2008-10-07 17:13:29 -04:00
M: _spill-integer compute-stack-frame*
drop frame-required? on ;
2008-10-07 17:13:29 -04:00
M: _spill-float compute-stack-frame*
drop frame-required? on ;
2008-10-07 17:13:29 -04:00
M: insn compute-stack-frame* drop ;
2008-10-07 17:13:29 -04:00
: compute-stack-frame ( insns -- )
[ compute-stack-frame* ] each ;
GENERIC: insert-pro/epilogues* ( insn -- )
2008-10-07 17:13:29 -04:00
M: ##stack-frame insert-pro/epilogues* drop ;
M: ##prologue insert-pro/epilogues*
2008-10-07 17:13:29 -04:00
drop frame-required? get [ stack-frame get _prologue ] when ;
M: ##epilogue insert-pro/epilogues*
2008-10-07 17:13:29 -04:00
drop frame-required? get [ stack-frame get _epilogue ] when ;
M: insn insert-pro/epilogues* , ;
: insert-pro/epilogues ( insns -- insns )
[ [ insert-pro/epilogues* ] each ] { } make ;
: build-stack-frame ( mr -- mr )
[
init-stack-frame-builder
[
2008-10-07 17:13:29 -04:00
[ compute-stack-frame ]
[ insert-pro/epilogues ]
bi
] change-instructions
] with-scope ;