]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
factor: trim using lists
[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
4 compiler.cfg.linearization cpu.architecture kernel layouts math
5 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 : compute-stack-frame ( cfg -- stack-frame/f )
57     dup cfg>insns f [ compute-stack-frame* or ] reduce [
58         stack-frame>>
59         allot-area-size get >>allot-area-size
60         allot-area-align get >>allot-area-align
61         param-area-size get >>params
62         finalize-stack-frame
63     ] [ drop f ] if ;
64
65 : build-stack-frame ( cfg -- )
66     0 param-area-size set
67     0 allot-area-size set
68     cell allot-area-align set
69     [ compute-stack-frame ] keep stack-frame<< ;