1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces accessors math.order assocs kernel sequences
4 combinators make classes words cpu.architecture
5 compiler.cfg.instructions compiler.cfg.registers
6 compiler.cfg.stack-frame ;
7 IN: compiler.cfg.build-stack-frame
9 SYMBOL: frame-required?
13 GENERIC: compute-stack-frame* ( insn -- )
15 : request-stack-frame ( stack-frame -- )
16 stack-frame [ max-stack-frame ] change ;
18 M: ##stack-frame compute-stack-frame*
20 stack-frame>> request-stack-frame ;
22 M: ##call compute-stack-frame*
23 word>> sub-primitive>> [ frame-required? on ] unless ;
25 M: _gc compute-stack-frame*
27 stack-frame new swap gc-root-size>> >>gc-root-size
30 M: _spill-counts compute-stack-frame*
31 counts>> stack-frame get (>>spill-counts) ;
33 M: insn compute-stack-frame*
34 class frame-required? word-prop [
38 \ _spill t frame-required? set-word-prop
40 : compute-stack-frame ( insns -- )
42 T{ stack-frame } clone stack-frame set
43 [ compute-stack-frame* ] each
44 stack-frame get dup stack-frame-size >>total-size drop ;
46 GENERIC: insert-pro/epilogues* ( insn -- )
48 M: ##stack-frame insert-pro/epilogues* drop ;
50 M: ##prologue insert-pro/epilogues*
51 drop frame-required? get [ stack-frame get _prologue ] when ;
53 M: ##epilogue insert-pro/epilogues*
54 drop frame-required? get [ stack-frame get _epilogue ] when ;
56 M: insn insert-pro/epilogues* , ;
58 : insert-pro/epilogues ( insns -- insns )
59 [ [ insert-pro/epilogues* ] each ] { } make ;
61 : build-stack-frame ( mr -- mr )
64 [ compute-stack-frame ]
65 [ insert-pro/epilogues ]