]> gitweb.factorcode.org Git - factor.git/blobdiff - 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
index 670e34e5f9b4282b6b82e75a263781d09c103b4b..96d4f881a8cb05b40f591169eba0028129fb3773 100644 (file)
@@ -1,73 +1,69 @@
 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces accessors math.order assocs kernel sequences
-combinators make classes words cpu.architecture layouts
-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
 
-SYMBOL: frame-required?
+SYMBOLS: param-area-size allot-area-size allot-area-align ;
 
-GENERIC: compute-stack-frame* ( insn -- )
+GENERIC: compute-stack-frame* ( insn -- )
 
-: request-stack-frame ( stack-frame -- )
-    frame-required? on
-    stack-frame [ max-stack-frame ] change ;
+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 t ;
 
-UNION: stack-frame-insn
-    ##alien-invoke
-    ##alien-indirect
-    ##alien-assembly
-    ##alien-callback ;
+M: alien-call-insn compute-stack-frame*
+    stack-size>> param-area-size [ max ] change t ;
 
-M: stack-frame-insn compute-stack-frame*
-    stack-frame>> request-stack-frame ;
+: vm-frame-required ( -- ? )
+    vm-stack-space param-area-size [ max ] change t ;
 
-M: ##call compute-stack-frame* drop frame-required? on ;
+M: ##call-gc compute-stack-frame* drop vm-frame-required ;
+M: ##box compute-stack-frame* drop vm-frame-required ;
+M: ##unbox compute-stack-frame* drop vm-frame-required ;
+M: ##box-long-long 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: ##gc compute-stack-frame*
-    frame-required? on
-    stack-frame new
-        swap tagged-values>> length cells >>gc-root-size
-        t >>calls-vm?
-    request-stack-frame ;
+M: ##call compute-stack-frame* drop t ;
+M: ##spill compute-stack-frame* drop t ;
+M: ##reload compute-stack-frame* drop t ;
 
-M: _spill-area-size compute-stack-frame*
-    n>> stack-frame get (>>spill-area-size) ;
+M: ##float>integer compute-stack-frame*
+    drop integer-float-needs-stack-frame? ;
 
-M: insn compute-stack-frame*
-    class frame-required? word-prop [
-        frame-required? on
-    ] when ;
+M: ##integer>float compute-stack-frame*
+    drop integer-float-needs-stack-frame? ;
 
-\ _spill t frame-required? set-word-prop
-\ ##unary-float-function t frame-required? set-word-prop
-\ ##binary-float-function t frame-required? set-word-prop
+M: insn compute-stack-frame* drop f ;
 
-: compute-stack-frame ( insns -- )
-    frame-required? off
-    stack-frame new stack-frame set
-    [ compute-stack-frame* ] each
-    stack-frame get dup stack-frame-size >>total-size drop ;
+: calculate-allot-area-base ( stack-frame -- n )
+    [ params>> ] [ allot-area-align>> ] bi align ;
 
-GENERIC: insert-pro/epilogues* ( insn -- )
+: calculate-spill-area-base ( stack-frame -- n )
+    [ allot-area-base>> ]
+    [ allot-area-size>> + ]
+    [ spill-area-align>> ] tri align ;
 
-M: ##prologue insert-pro/epilogues*
-    drop frame-required? get [ stack-frame get _prologue ] when ;
+: finalize-stack-frame ( stack-frame -- stack-frame )
+    dup calculate-allot-area-base >>allot-area-base
+    dup calculate-spill-area-base >>spill-area-base
+    dup stack-frame-size >>total-size ;
 
-M: ##epilogue insert-pro/epilogues*
-    drop frame-required? get [ stack-frame get _epilogue ] when ;
+: 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
+    ] [ drop f ] if ;
 
-M: insn insert-pro/epilogues* , ;
-
-: insert-pro/epilogues ( insns -- insns )
-    [ [ insert-pro/epilogues* ] each ] { } make ;
-
-: build-stack-frame ( mr -- mr )
-    [
-        [
-            [ compute-stack-frame ]
-            [ insert-pro/epilogues ]
-            bi
-        ] change-instructions
-    ] with-scope ;
+: build-stack-frame ( cfg -- )
+    0 param-area-size set
+    0 allot-area-size set
+    cell allot-area-align set
+    [ compute-stack-frame ] keep stack-frame<< ;