]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
FFI rewrite part 5: return value boxing and callback parameter boxing now uses vregs...
[factor.git] / basis / compiler / cfg / build-stack-frame / build-stack-frame.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces accessors math math.order assocs kernel sequences
4 combinators classes words cpu.architecture layouts compiler.cfg
5 compiler.cfg.rpo compiler.cfg.instructions
6 compiler.cfg.registers 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: ##stack-frame compute-stack-frame*
18     stack-frame>> request-stack-frame ;
19
20 M: ##call-gc compute-stack-frame*
21     drop
22     frame-required? on
23     stack-frame new t >>calls-vm? request-stack-frame ;
24
25 M: ##call compute-stack-frame* drop frame-required? on ;
26
27 M: ##alien-callback compute-stack-frame* drop frame-required? on ;
28
29 M: insn compute-stack-frame*
30     class "frame-required?" word-prop
31     [ frame-required? on ] when ;
32
33 : initial-stack-frame ( -- stack-frame )
34     stack-frame new cfg get spill-area-size>> >>spill-area-size ;
35
36 : compute-stack-frame ( cfg -- )
37     initial-stack-frame stack-frame set
38     [ spill-area-size>> 0 > frame-required? set ]
39     [ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ] bi
40     stack-frame get dup stack-frame-size >>total-size drop ;
41
42 : build-stack-frame ( cfg -- cfg )
43     [
44         [ compute-stack-frame ]
45         [
46             frame-required? get stack-frame get f ?
47             >>stack-frame
48         ] bi
49     ] with-scope ;