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