diff --git a/basis/compiler/cfg/build-stack-frame/build-stack-frame-docs.factor b/basis/compiler/cfg/build-stack-frame/build-stack-frame-docs.factor index f3a0a989a1..17828cf663 100644 --- a/basis/compiler/cfg/build-stack-frame/build-stack-frame-docs.factor +++ b/basis/compiler/cfg/build-stack-frame/build-stack-frame-docs.factor @@ -1,23 +1,25 @@ -USING: assocs compiler.cfg compiler.cfg.stack-frame help.markup help.syntax ; +USING: assocs compiler.cfg compiler.cfg.instructions compiler.cfg.stack-frame +help.markup help.syntax kernel ; IN: compiler.cfg.build-stack-frame -ARTICLE: "compiler.cfg.build-stack-frame" "Computing stack frame size and layout" -"The " { $vocab-link "compiler.cfg.build-stack-frame" } " vocab builds stack frames for cfg:s." ; +HELP: compute-stack-frame +{ $values { "cfg" cfg } { "stack-frame/f" stack-frame } } +{ $description "Initializes a stack frame for a cfg, if it needs one." } +{ $see-also compute-stack-frame* } ; + +HELP: compute-stack-frame* +{ $values { "insn" insn } { "?" boolean } } +{ $description "Computes required stack frame size for the instruction. If a stack frame is needed, then " { $link t } " is returned." } ; HELP: param-area-size { $var-description "Temporary variable used when building stack frames to calculate the parameter area size." } { $see-also build-stack-frame } ; -HELP: frame-required? -{ $var-description "Whether the word being compiled requires a stack frame or not. Most words does, but very simple words does not." } ; - -HELP: compute-stack-frame -{ $values { "cfg" cfg } { "stack-frame/f" stack-frame } } -{ $description "Initializes a stack frame for a cfg, if it needs one." } -{ $see-also frame-required? } ; - HELP: finalize-stack-frame { $values { "stack-frame" stack-frame } } { $description "Calculates and stores the " { $slot "allot-area-base" } ", " { $slot "spill-area-base" } " and " { $slot "total-size" } " slots of a stack frame." } ; +ARTICLE: "compiler.cfg.build-stack-frame" "Computing stack frame size and layout" +"The " { $vocab-link "compiler.cfg.build-stack-frame" } " vocab builds stack frames for cfg:s." ; + ABOUT: "compiler.cfg.build-stack-frame" diff --git a/basis/compiler/cfg/build-stack-frame/build-stack-frame-tests.factor b/basis/compiler/cfg/build-stack-frame/build-stack-frame-tests.factor index cb00917974..9acd7215f0 100644 --- a/basis/compiler/cfg/build-stack-frame/build-stack-frame-tests.factor +++ b/basis/compiler/cfg/build-stack-frame/build-stack-frame-tests.factor @@ -1,6 +1,7 @@ -USING: accessors compiler.cfg compiler.cfg.build-stack-frame -compiler.cfg.stack-frame cpu.x86 kernel math namespaces slots.syntax -tools.test ; +USING: accessors compiler.cfg.build-stack-frame +compiler.cfg.instructions compiler.cfg.linearization +compiler.cfg.stack-frame compiler.cfg.utilities cpu.x86 kernel math +sequences slots.syntax tools.test ; IN: compiler.cfg.build-stack-frame.tests { @@ -25,6 +26,17 @@ IN: compiler.cfg.build-stack-frame.tests ] unit-test { f } [ - t frame-required? set - f f dup build-stack-frame stack-frame>> + { } insns>cfg dup build-stack-frame stack-frame>> +] unit-test + +{ t } [ + { T{ ##call-gc } } insns>cfg dup build-stack-frame + stack-frame>> stack-frame? +] unit-test + +{ 0 } [ + { + T{ ##call-gc } + T{ ##local-allot { dst 1 } { size 32 } { align 8 } } + } insns>cfg dup build-stack-frame cfg>insns last offset>> ] unit-test diff --git a/basis/compiler/cfg/build-stack-frame/build-stack-frame.factor b/basis/compiler/cfg/build-stack-frame/build-stack-frame.factor index a0bae5ced4..c353d378f1 100644 --- a/basis/compiler/cfg/build-stack-frame/build-stack-frame.factor +++ b/basis/compiler/cfg/build-stack-frame/build-stack-frame.factor @@ -1,31 +1,25 @@ ! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors compiler.cfg.instructions compiler.cfg.rpo -compiler.cfg.stack-frame cpu.architecture kernel layouts locals -math math.order namespaces sequences ; +USING: accessors compiler.cfg.instructions compiler.cfg.linearization +compiler.cfg.rpo compiler.cfg.stack-frame cpu.architecture kernel layouts +locals 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 ; @@ -34,17 +28,17 @@ 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: ##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 ; @@ -69,12 +63,10 @@ M: insn compute-stack-frame* drop ; finalize-stack-frame ; : compute-stack-frame ( cfg -- stack-frame/f ) - [ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ] - [ frame-required? get [ ] [ drop f ] if ] - bi ; + dup cfg>insns [ compute-stack-frame* ] map [ ] any? + [ ] [ drop f ] if ; : build-stack-frame ( cfg -- ) - f frame-required? set 0 param-area-size set 0 allot-area-size set cell allot-area-align set