]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / compiler / cfg / build-stack-frame / build-stack-frame.factor
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
8
9 SYMBOL: frame-required?
10
11 GENERIC: compute-stack-frame* ( insn -- )
12
13 : request-stack-frame ( stack-frame -- )
14     frame-required? on
15     stack-frame [ max-stack-frame ] change ;
16
17 UNION: stack-frame-insn
18     ##alien-invoke
19     ##alien-indirect
20     ##alien-callback ;
21
22 M: stack-frame-insn compute-stack-frame*
23     stack-frame>> request-stack-frame ;
24
25 M: ##call compute-stack-frame*
26     word>> sub-primitive>> [ frame-required? on ] unless ;
27
28 M: ##gc compute-stack-frame*
29     frame-required? on
30     stack-frame new swap tagged-values>> length cells >>gc-root-size
31     request-stack-frame ;
32
33 M: _spill-area-size compute-stack-frame*
34     n>> stack-frame get (>>spill-area-size) ;
35
36 M: insn compute-stack-frame*
37     class frame-required? word-prop [
38         frame-required? on
39     ] when ;
40
41 \ _spill t frame-required? set-word-prop
42 \ ##unary-float-function t frame-required? set-word-prop
43 \ ##binary-float-function t frame-required? set-word-prop
44
45 : compute-stack-frame ( insns -- )
46     frame-required? off
47     stack-frame new stack-frame set
48     [ compute-stack-frame* ] each
49     stack-frame get dup stack-frame-size >>total-size drop ;
50
51 GENERIC: insert-pro/epilogues* ( insn -- )
52
53 M: ##prologue insert-pro/epilogues*
54     drop frame-required? get [ stack-frame get _prologue ] when ;
55
56 M: ##epilogue insert-pro/epilogues*
57     drop frame-required? get [ stack-frame get _epilogue ] when ;
58
59 M: insn insert-pro/epilogues* , ;
60
61 : insert-pro/epilogues ( insns -- insns )
62     [ [ insert-pro/epilogues* ] each ] { } make ;
63
64 : build-stack-frame ( mr -- mr )
65     [
66         [
67             [ compute-stack-frame ]
68             [ insert-pro/epilogues ]
69             bi
70         ] change-instructions
71     ] with-scope ;