! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces accessors math math.order assocs kernel
-sequences combinators classes words system fry locals
-cpu.architecture layouts compiler.cfg compiler.cfg.rpo
-compiler.cfg.instructions compiler.cfg.registers
-compiler.cfg.stack-frame ;
+USING: accessors compiler.cfg.instructions
+compiler.cfg.linearization cpu.architecture kernel layouts math
+math.order namespaces sequences ;
IN: compiler.cfg.build-stack-frame
-SYMBOLS: param-area-size allot-area-size allot-area-align
-frame-required? ;
+SYMBOLS: param-area-size allot-area-size allot-area-align ;
-: frame-required ( -- ) frame-required? on ;
+GENERIC: compute-stack-frame* ( insn -- ? )
-GENERIC: compute-stack-frame* ( insn -- )
-
-M:: ##local-allot compute-stack-frame* ( insn -- )
- frame-required
+M:: ##local-allot compute-stack-frame* ( insn -- ? )
insn size>> :> s
insn align>> :> a
allot-area-align [ a max ] change
- allot-area-size [ a align [ insn offset<< ] [ s + ] bi ] change ;
+ allot-area-size [ a align [ insn offset<< ] [ s + ] bi ] change t ;
M: alien-call-insn compute-stack-frame*
- frame-required
- stack-size>> param-area-size [ max ] change ;
+ stack-size>> param-area-size [ max ] change t ;
-: vm-frame-required ( -- )
- frame-required
- vm-stack-space param-area-size [ max ] change ;
+: vm-frame-required ( -- ? )
+ vm-stack-space param-area-size [ max ] change t ;
M: ##call-gc compute-stack-frame* drop vm-frame-required ;
M: ##box compute-stack-frame* drop vm-frame-required ;
M: ##callback-inputs compute-stack-frame* drop vm-frame-required ;
M: ##callback-outputs compute-stack-frame* drop vm-frame-required ;
-M: ##call compute-stack-frame* drop frame-required ;
-M: ##spill compute-stack-frame* drop frame-required ;
-M: ##reload compute-stack-frame* drop frame-required ;
+M: ##call compute-stack-frame* drop t ;
+M: ##spill compute-stack-frame* drop t ;
+M: ##reload compute-stack-frame* drop t ;
M: ##float>integer compute-stack-frame*
- drop integer-float-needs-stack-frame? [ frame-required ] when ;
+ drop integer-float-needs-stack-frame? ;
M: ##integer>float compute-stack-frame*
- drop integer-float-needs-stack-frame? [ frame-required ] when ;
+ drop integer-float-needs-stack-frame? ;
-M: insn compute-stack-frame* drop ;
+M: insn compute-stack-frame* drop f ;
: calculate-allot-area-base ( stack-frame -- n )
[ params>> ] [ allot-area-align>> ] bi align ;
dup calculate-spill-area-base >>spill-area-base
dup stack-frame-size >>total-size ;
-: <stack-frame> ( cfg -- stack-frame )
- stack-frame new
- over spill-area-size>> >>spill-area-size
- swap spill-area-align>> >>spill-area-align
+: compute-stack-frame ( cfg -- stack-frame/f )
+ dup cfg>insns f [ compute-stack-frame* or ] reduce [
+ stack-frame>>
allot-area-size get >>allot-area-size
allot-area-align get >>allot-area-align
param-area-size get >>params
- finalize-stack-frame ;
-
-: compute-stack-frame ( cfg -- stack-frame/f )
- [ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ]
- [ frame-required? get [ <stack-frame> ] [ drop f ] if ]
- bi ;
+ finalize-stack-frame
+ ] [ drop f ] if ;
: build-stack-frame ( cfg -- )
0 param-area-size set