From d0aae5cc20d18d8d237943e166f6764d0406875c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 13 Sep 2015 07:14:46 +0200 Subject: [PATCH] compiler.cfg.linearization: number-blocks can set the number>> accessor instead of using the numbers dynamic variable --- basis/compiler/cfg/debugger/debugger.factor | 4 ++-- .../cfg/linearization/linearization-docs.factor | 6 +----- .../cfg/linearization/linearization-tests.factor | 14 +++++++++++--- .../cfg/linearization/linearization.factor | 6 +----- basis/compiler/codegen/codegen.factor | 4 +--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/basis/compiler/cfg/debugger/debugger.factor b/basis/compiler/cfg/debugger/debugger.factor index 9f62aa2ad2..0017c61564 100644 --- a/basis/compiler/cfg/debugger/debugger.factor +++ b/basis/compiler/cfg/debugger/debugger.factor @@ -59,11 +59,11 @@ M: insn insn. tuple>array but-last [ ] interleave nl ; : block. ( bb -- ) - "=== Basic block #" write dup block-number . nl + "=== Basic block #" write dup number>> . nl dup instructions>> [ insn. ] each nl successors>> [ "Successors: " write - [ block-number unparse ] map ", " join print nl + [ number>> unparse ] map ", " join print nl ] unless-empty ; : cfg. ( cfg -- ) diff --git a/basis/compiler/cfg/linearization/linearization-docs.factor b/basis/compiler/cfg/linearization/linearization-docs.factor index d6ba8017c0..de42ce9d1c 100644 --- a/basis/compiler/cfg/linearization/linearization-docs.factor +++ b/basis/compiler/cfg/linearization/linearization-docs.factor @@ -10,10 +10,6 @@ HELP: linearization-order { $description "Lists the basic blocks in linearization order. That is, the order in which they will be written in the generated assembly code." } { $see-also generate reverse-post-order } ; -HELP: block-number -{ $values { "bb" basic-block } { "n" integer } } -{ $description "Retrieves this blocks block number. Must not be called before " { $link number-blocks } "." } ; - HELP: number-blocks { $values { "bbs" sequence } } -{ $description "Associate each block with a block number and save the result in the " { $link numbers } " map." } ; +{ $description "Assigns the " { $slot "number" } " slot of each " { $link basic-block } " given it's sequence index." } ; diff --git a/basis/compiler/cfg/linearization/linearization-tests.factor b/basis/compiler/cfg/linearization/linearization-tests.factor index 674b7e0a40..fb77d831cf 100644 --- a/basis/compiler/cfg/linearization/linearization-tests.factor +++ b/basis/compiler/cfg/linearization/linearization-tests.factor @@ -17,12 +17,15 @@ V{ } 2 test-bb 0 get block>cfg linearization-order [ number>> ] map ] unit-test -! (linearization-order) -{ { 10 20 30 } } [ +: two-successors-cfg ( -- cfg ) V{ } 10 insns>block [ V{ } 20 insns>block connect-bbs ] keep [ V{ } 30 insns>block connect-bbs ] keep - block>cfg (linearization-order) [ number>> ] map + block>cfg ; + +! (linearization-order) +{ { 10 20 30 } } [ + two-successors-cfg (linearization-order) [ number>> ] map ] unit-test { { 0 1 2 3 4 5 } } [ @@ -43,3 +46,8 @@ V{ } 2 test-bb V{ } 10 insns>block [ process-block ] V{ } make [ number>> ] map ] unit-test + +! number-blocks +{ { 0 1 2 } } [ + two-successors-cfg linearization-order dup number-blocks [ number>> ] map +] unit-test diff --git a/basis/compiler/cfg/linearization/linearization.factor b/basis/compiler/cfg/linearization/linearization.factor index b5abf84fed..332c18bdcb 100644 --- a/basis/compiler/cfg/linearization/linearization.factor +++ b/basis/compiler/cfg/linearization/linearization.factor @@ -66,12 +66,8 @@ PRIVATE> ] } cleave ; -SYMBOL: numbers - -: block-number ( bb -- n ) numbers get at ; - : number-blocks ( bbs -- ) - H{ } zip-index-as numbers set ; + [ >>number drop ] each-index ; : blocks>insns ( bbs -- insns ) [ instructions>> ] map concat ; diff --git a/basis/compiler/codegen/codegen.factor b/basis/compiler/codegen/codegen.factor index c48f3d5b94..27e1c1d1c9 100755 --- a/basis/compiler/codegen/codegen.factor +++ b/basis/compiler/codegen/codegen.factor @@ -23,9 +23,7 @@ SYMBOL: labels labels get [ drop