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