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