]> 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 M: ##alien-invoke compute-stack-frame*
18     stack-frame>> request-stack-frame ;
19
20 M: ##alien-indirect compute-stack-frame*
21     stack-frame>> request-stack-frame ;
22
23 M: ##alien-callback compute-stack-frame*
24     stack-frame>> request-stack-frame ;
25
26 M: ##call compute-stack-frame*
27     word>> sub-primitive>> [ frame-required? on ] unless ;
28
29 M: _gc compute-stack-frame*
30     frame-required? on
31     stack-frame new swap gc-root-size>> cells >>gc-root-size
32     request-stack-frame ;
33
34 M: _spill-area-size compute-stack-frame*
35     n>> stack-frame get (>>spill-area-size) ;
36
37 M: insn compute-stack-frame*
38     class frame-required? word-prop [
39         frame-required? on
40     ] when ;
41
42 \ _spill t frame-required? set-word-prop
43
44 : compute-stack-frame ( insns -- )
45     frame-required? off
46     stack-frame new stack-frame set
47     [ compute-stack-frame* ] each
48     stack-frame get dup stack-frame-size >>total-size drop ;
49
50 GENERIC: insert-pro/epilogues* ( insn -- )
51
52 M: ##prologue insert-pro/epilogues*
53     drop frame-required? get [ stack-frame get _prologue ] when ;
54
55 M: ##epilogue insert-pro/epilogues*
56     drop frame-required? get [ stack-frame get _epilogue ] when ;
57
58 M: insn insert-pro/epilogues* , ;
59
60 : insert-pro/epilogues ( insns -- insns )
61     [ [ insert-pro/epilogues* ] each ] { } make ;
62
63 : build-stack-frame ( mr -- mr )
64     [
65         [
66             [ compute-stack-frame ]
67             [ insert-pro/epilogues ]
68             bi
69         ] change-instructions
70     ] with-scope ;