]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
compiler: now that FFI has been deconcatenatized, we no longer need the special ...
[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
4 sequences combinators classes words system fry locals
5 cpu.architecture layouts compiler.cfg compiler.cfg.rpo
6 compiler.cfg.instructions compiler.cfg.registers
7 compiler.cfg.stack-frame ;
8 IN: compiler.cfg.build-stack-frame
9
10 SYMBOLS: param-area-size allot-area-size allot-area-align
11 frame-required? ;
12
13 : frame-required ( -- ) frame-required? on ;
14
15 GENERIC: compute-stack-frame* ( insn -- )
16
17 M:: ##local-allot compute-stack-frame* ( insn -- )
18     frame-required
19     insn size>> :> s
20     insn align>> :> a
21     allot-area-align [ a max ] change
22     allot-area-size [ a align [ insn offset<< ] [ s + ] bi ] change ;
23
24 M: alien-call-insn compute-stack-frame*
25     frame-required
26     stack-size>> param-area-size [ max ] change ;
27
28 : vm-frame-required ( -- )
29     frame-required
30     vm-stack-space param-area-size [ max ] change ;
31
32 M: ##call-gc compute-stack-frame* drop vm-frame-required ;
33 M: ##box compute-stack-frame* drop vm-frame-required ;
34 M: ##unbox compute-stack-frame* drop vm-frame-required ;
35 M: ##box-long-long compute-stack-frame* drop vm-frame-required ;
36 M: ##callback-inputs compute-stack-frame* drop vm-frame-required ;
37 M: ##callback-outputs compute-stack-frame* drop vm-frame-required ;
38
39 M: ##call compute-stack-frame* drop frame-required ;
40 M: ##spill compute-stack-frame* drop frame-required ;
41 M: ##reload compute-stack-frame* drop frame-required ;
42
43 M: ##float>integer compute-stack-frame*
44     drop integer-float-needs-stack-frame? [ frame-required ] when ;
45
46 M: ##integer>float compute-stack-frame*
47     drop integer-float-needs-stack-frame? [ frame-required ] when ;
48
49 M: insn compute-stack-frame* drop ;
50
51 : finalize-stack-frame ( stack-frame -- )
52     dup [ params>> ] [ allot-area-align>> ] bi align >>allot-area-base
53     dup [ [ allot-area-base>> ] [ allot-area-size>> ] bi + ] [ spill-area-align>> ] bi align >>spill-area-base
54     dup stack-frame-size >>total-size drop ;
55
56 : <stack-frame> ( cfg -- stack-frame )
57     [ stack-frame new ] dip
58     [ spill-area-size>> >>spill-area-size ]
59     [ spill-area-align>> >>spill-area-align ] bi
60     allot-area-size get >>allot-area-size
61     allot-area-align get >>allot-area-align
62     param-area-size get >>params
63     dup finalize-stack-frame ;
64
65 : compute-stack-frame ( cfg -- stack-frame/f )
66     [ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ]
67     [ frame-required? get [ <stack-frame> ] [ drop f ] if ]
68     bi ;
69
70 : build-stack-frame ( cfg -- cfg )
71     0 param-area-size set
72     0 allot-area-size set
73     cell allot-area-align set
74     dup compute-stack-frame >>stack-frame ;