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 layouts
5 compiler.cfg.instructions compiler.cfg.registers
6 compiler.cfg.stack-frame ;
7 IN: compiler.cfg.build-stack-frame
9 SYMBOL: frame-required?
11 GENERIC: compute-stack-frame* ( insn -- )
13 : request-stack-frame ( stack-frame -- )
15 stack-frame [ max-stack-frame ] change ;
17 UNION: stack-frame-insn
22 M: stack-frame-insn compute-stack-frame*
23 stack-frame>> request-stack-frame ;
25 M: ##call compute-stack-frame*
26 word>> sub-primitive>> [ frame-required? on ] unless ;
28 M: ##gc compute-stack-frame*
31 swap tagged-values>> length cells >>gc-root-size
35 M: _spill-area-size compute-stack-frame*
36 n>> stack-frame get (>>spill-area-size) ;
38 M: insn compute-stack-frame*
39 class frame-required? word-prop [
43 \ _spill t frame-required? set-word-prop
44 \ ##unary-float-function t frame-required? set-word-prop
45 \ ##binary-float-function t frame-required? set-word-prop
47 : compute-stack-frame ( insns -- )
49 stack-frame new stack-frame set
50 [ compute-stack-frame* ] each
51 stack-frame get dup stack-frame-size >>total-size drop ;
53 GENERIC: insert-pro/epilogues* ( insn -- )
55 M: ##prologue insert-pro/epilogues*
56 drop frame-required? get [ stack-frame get _prologue ] when ;
58 M: ##epilogue insert-pro/epilogues*
59 drop frame-required? get [ stack-frame get _epilogue ] when ;
61 M: insn insert-pro/epilogues* , ;
63 : insert-pro/epilogues ( insns -- insns )
64 [ [ insert-pro/epilogues* ] each ] { } make ;
66 : build-stack-frame ( mr -- mr )
69 [ compute-stack-frame ]
70 [ insert-pro/epilogues ]