]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
Merge branch 'new_gc' of git://factorcode.org/git/factor into new_gc
[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
31         swap tagged-values>> length cells >>gc-root-size
32         t >>calls-vm?
33     request-stack-frame ;
34
35 M: _spill-area-size compute-stack-frame*
36     n>> stack-frame get (>>spill-area-size) ;
37
38 M: insn compute-stack-frame*
39     class frame-required? word-prop [
40         frame-required? on
41     ] when ;
42
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
46
47 : compute-stack-frame ( insns -- )
48     frame-required? off
49     stack-frame new stack-frame set
50     [ compute-stack-frame* ] each
51     stack-frame get dup stack-frame-size >>total-size drop ;
52
53 GENERIC: insert-pro/epilogues* ( insn -- )
54
55 M: ##prologue insert-pro/epilogues*
56     drop frame-required? get [ stack-frame get _prologue ] when ;
57
58 M: ##epilogue insert-pro/epilogues*
59     drop frame-required? get [ stack-frame get _epilogue ] when ;
60
61 M: insn insert-pro/epilogues* , ;
62
63 : insert-pro/epilogues ( insns -- insns )
64     [ [ insert-pro/epilogues* ] each ] { } make ;
65
66 : build-stack-frame ( mr -- mr )
67     [
68         [
69             [ compute-stack-frame ]
70             [ insert-pro/epilogues ]
71             bi
72         ] change-instructions
73     ] with-scope ;