compiler.cfg.build-stack-frame: refactoring which removes the
frame-required? variabledb4
parent
80ea6b8997
commit
d24733e703
|
@ -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"
|
||||
|
|
|
@ -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 <basic-block> <cfg> 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
|
||||
|
|
|
@ -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 [ <stack-frame> ] [ drop f ] if ]
|
||||
bi ;
|
||||
dup cfg>insns [ compute-stack-frame* ] map [ ] any?
|
||||
[ <stack-frame> ] [ 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
|
||||
|
|
Loading…
Reference in New Issue