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