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

67 lines
1.8 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
2008-10-19 02:10:21 -04:00
combinators make cpu.architecture compiler.cfg.instructions
2008-10-07 21:00:38 -04:00
compiler.cfg.instructions.syntax compiler.cfg.registers ;
IN: compiler.cfg.stack-frame
SYMBOL: frame-required?
SYMBOL: spill-counts
2008-10-07 17:13:29 -04:00
GENERIC: compute-stack-frame* ( insn -- )
2008-10-07 17:13:29 -04:00
: max-stack-frame ( frame1 frame2 -- frame3 )
2008-10-19 02:10:21 -04:00
[ stack-frame new ] 2dip
[ [ params>> ] bi@ max >>params ]
[ [ return>> ] bi@ max >>return ]
2bi ;
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-22 00:17:32 -04:00
M: ##gc compute-stack-frame*
drop frame-required? on ;
M: ##call compute-stack-frame*
drop frame-required? on ;
2008-10-19 02:10:21 -04:00
M: _spill compute-stack-frame*
drop frame-required? on ;
2008-10-19 02:10:21 -04:00
M: _spill-counts compute-stack-frame*
counts>> stack-frame get (>>spill-counts) ;
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 -- )
2008-10-19 02:10:21 -04:00
frame-required? off
T{ stack-frame } clone stack-frame set
[ compute-stack-frame* ] each
stack-frame get dup stack-frame-size >>total-size drop ;
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 )
[
[
2008-10-07 17:13:29 -04:00
[ compute-stack-frame ]
[ insert-pro/epilogues ]
bi
] change-instructions
] with-scope ;