USING: compiler.cfg compiler.cfg.stacks.local compiler.tree help.markup
-help.syntax literals math multiline quotations sequences ;
+help.syntax literals make math multiline quotations sequences ;
IN: compiler.cfg.builder.blocks
<<
STRING: ex-emit-trivial-block
-USING: compiler.cfg.builder.blocks prettyprint ;
-initial-basic-block [ [ gensym ##call, ] emit-trivial-block ] { } make drop
-basic-block get .
+USING: compiler.cfg.builder.blocks make prettyprint ;
+<basic-block> set-basic-block [ [ gensym ##call, ] emit-trivial-block ] { } make drop basic-block get .
T{ basic-block
{ id 2040412 }
{ successors
{ $values { "pair/f" "two-tuple" } }
{ $description "pair is { final-bb final-height }" } ;
-HELP: initial-basic-block
-{ $description "Creates an initial empty " { $link basic-block } " and stores it in the basic-block dynamic variable." } ;
-
HELP: make-kill-block
{ $description "Marks the current " { $link basic-block } " being processed as a kill block." } ;
+HELP: set-basic-block
+{ $values { "basic-block" basic-block } }
+{ $description "Sets the given blocks as the current one by storing it in the basic-block dynamic variable. If it has any " { $slot "instructions" } " the current " { $link building } " is set to those." } ;
+
HELP: set-successors
{ $values { "successor" basic-block } { "blocks" sequence } }
{ $description "Set the successor of each block to " { $slot "successor" } "." } ;
-USING: accessors compiler.cfg compiler.cfg.builder.blocks kernel sequences
-tools.test ;
+USING: accessors compiler.cfg compiler.cfg.builder.blocks compiler.cfg.stacks
+kernel namespaces sequences tools.test ;
IN: compiler.cfg.builder.blocks.tests
{
[ set-successors ] keep
[ successors>> first number>> ] map
] unit-test
+
+{ 33 } [
+ begin-stack-analysis <basic-block> 33 >>number basic-block set
+ (begin-basic-block)
+ basic-block get predecessors>> first number>>
+] unit-test
! Copyright (C) 2009, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays compiler.cfg compiler.cfg.instructions
-compiler.cfg.stacks compiler.cfg.stacks.local kernel make math
-namespaces sequences ;
+compiler.cfg.stacks compiler.cfg.stacks.local compiler.cfg.utilities kernel
+make math namespaces sequences ;
SLOT: in-d
SLOT: out-d
IN: compiler.cfg.builder.blocks
[ basic-block set ] [ instructions>> building set ] bi
begin-local-analysis ;
-: initial-basic-block ( -- )
- <basic-block> set-basic-block ;
-
: end-basic-block ( -- )
basic-block get [ end-local-analysis ] when
building off
basic-block off ;
: (begin-basic-block) ( -- )
- <basic-block>
- basic-block get [ dupd successors>> push ] when*
- set-basic-block ;
+ <basic-block> basic-block get [ over connect-bbs ] when* set-basic-block ;
: begin-basic-block ( -- )
basic-block get [ end-local-analysis ] when
STRING: ex-emit-call
USING: compiler.cfg.builder compiler.cfg.builder.blocks compiler.cfg.stacks
kernel make prettyprint ;
-begin-stack-analysis initial-basic-block \ dummy 3 [ emit-call ] { } make drop
+begin-stack-analysis <basic-block> set-basic-block
+\ dummy 3 [ emit-call ] { } make drop
height-state basic-block [ get . ] bi@
{ { 3 0 } { 0 0 } }
T{ basic-block
basic-block get successors>> length
] unit-test
+! begin-cfg
+SYMBOL: foo
+
+{ foo } [
+ begin-stack-analysis \ foo f begin-cfg word>>
+] unit-test
+
! store-shuffle
{
H{ { D 2 1 } }
SYMBOL: loops
: begin-cfg ( word label -- cfg )
- initial-basic-block
H{ } clone loops set
- [ basic-block get ] 2dip <cfg> dup cfg set ;
+ <basic-block> dup set-basic-block <cfg> dup cfg set ;
: begin-procedure ( word label -- )
begin-cfg procedures get push ;
{ $values { "bb" basic-block } }
{ $description "Creates a new empty basic block. The " { $slot "id" } " slot is initialized with the value of the basic-block " { $link counter } "." } ;
+HELP: <cfg>
+{ $values { "entry" basic-block } { "word" word } { "label" "label" } { "cfg" cfg } }
+{ $description "Constructor for " { $link cfg } "." } ;
+
HELP: cfg
{ $class-description
"Call flow graph. It has the following slots:"
--- /dev/null
+USING: accessors compiler.cfg kernel tools.test ;
+IN: compiler.cfg.tests
+
+{
+ "word"
+ "label"
+} [
+ "word" "label" <basic-block> <cfg>
+ [ word>> ] [ label>> ] bi
+] unit-test
post-order linear-order
predecessors-valid? dominance-valid? loops-valid? ;
-: <cfg> ( entry word label -- cfg )
+: <cfg> ( word label entry -- cfg )
cfg new
+ swap >>entry
swap >>label
- swap >>word
- swap >>entry ;
+ swap >>word ;
: cfg-changed ( cfg -- )
f >>post-order