Changed things in the transformations directory in light of the new step count

This commit is contained in:
Neil Brown 2009-01-28 23:46:04 +00:00
parent 594d7ef242
commit 6693a8b8b9
3 changed files with 17 additions and 12 deletions

View File

@ -227,7 +227,8 @@ testTransformConstr0 = TestCase $ testPass "transformConstr0" exp transformConst
orig = A.Spec m (A.Specification m (simpleName "arr") $
A.IsExpr m A.ValAbbrev t $ A.ExprConstr m $
A.RepConstr m t (simpleName "x") (A.For m (intLiteral 0) (intLiteral 10))
A.RepConstr m t (simpleName "x") (A.For m (intLiteral 0) (intLiteral 10)
(intLiteral 1))
(exprVariable "x")) skipP
exp = nameAndStopCaringPattern "indexVar" "i" $ mkPattern exp'
exp' = A.Spec m (A.Specification m (simpleName "arr") (A.Declaration m t)) $
@ -236,7 +237,7 @@ testTransformConstr0 = TestCase $ testPass "transformConstr0" exp transformConst
(A.Declaration m A.Int)) $
A.Several m [A.Only m $ A.Assign m [variable "i"] $
A.ExpressionList m [intLiteral 0],
A.Spec m (A.Specification m (simpleName "x") $ A.Rep m (A.For m (intLiteral 0) (intLiteral 10))) $
A.Spec m (A.Specification m (simpleName "x") $ A.Rep m (A.For m (intLiteral 0) (intLiteral 10) (intLiteral 1))) $
A.Only m $ A.Seq m $ A.Several m
[A.Only m $ A.Assign m
[A.SubscriptedVariable m (A.Subscript m A.NoCheck $
@ -586,7 +587,7 @@ testPullRepCounts = TestList
,forAllThree $ \blockType -> testOccamPassTransform "testPullRepCounts 5" (nameAndStopCaringPattern "nonce" "A")
(blockType
[decl' (simpleName "X")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 6)))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 6) (intLiteral 1)))
A.Original A.NameUser []
]
`becomes`
@ -594,7 +595,7 @@ testPullRepCounts = TestList
[decl' (simpleName "A")
(A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6) A.ValAbbrev A.NameNonce
[decl' (simpleName "X")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (exprVariable "A")))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (exprVariable "A") (intLiteral 1)))
A.Original A.NameUser []
]
]
@ -604,10 +605,10 @@ testPullRepCounts = TestList
(nameAndStopCaringPattern "nonce1" "A" . nameAndStopCaringPattern "nonce2" "B")
(blockType
[decl' (simpleName "X")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 6)))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 6) (intLiteral 1)))
A.Original A.NameUser
[decl' (simpleName "Y")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 1) (intLiteral 8)))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 1) (intLiteral 8) (intLiteral 2)))
A.Original A.NameUser []
]
]
@ -616,12 +617,13 @@ testPullRepCounts = TestList
[decl' (simpleName "A")
(A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6) A.ValAbbrev A.NameNonce
[decl' (simpleName "X")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (exprVariable "A")))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (exprVariable "A") (intLiteral 1)))
A.Original A.NameUser
[decl' (simpleName "B")
(A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 8) A.ValAbbrev A.NameNonce
[decl' (simpleName "Y")
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 1) (exprVariable "B")))
(A.Rep emptyMeta (A.For emptyMeta (intLiteral 1) (exprVariable "B")
(intLiteral 2)))
A.Original A.NameUser
[]
]
@ -642,7 +644,8 @@ testPullRepCounts = TestList
(return ())
where
code = (f $ A.Spec emptyMeta (A.Specification emptyMeta (simpleName
"i") $ A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 5))) $ A.Several emptyMeta [])
"i") $ A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 5)
(intLiteral 1))) $ A.Several emptyMeta [])
testRemoveNesting :: Test

View File

@ -159,6 +159,8 @@ expandArrayLiterals = pass "Expand array literals"
-- Therefore, we only need to pull up the counts for SEQ, PAR and ALT
--
-- TODO for simplification, we could avoid pulling up replication counts that are known to be constants
--
-- TODO we should also pull up the step counts
pullRepCounts :: Pass
pullRepCounts = pass "Pull up replicator counts for SEQs, PARs and ALTs"
(Prop.agg_namesDone ++ Prop.agg_typesDone)
@ -170,10 +172,10 @@ pullRepCounts = pass "Pull up replicator counts for SEQs, PARs and ALTs"
where
pullRepCount :: Data a => A.Structured a -> PassM (A.Structured a)
pullRepCount (A.Spec m (A.Specification mspec n (A.Rep mrep (A.For mfor
from for))) scope)
from for step))) scope)
= do t <- astTypeOf for
spec@(A.Specification _ nonceName _) <- makeNonceIsExpr "rep_for" mspec t for
let newSpec = (A.Rep mrep (A.For mfor from (A.ExprVariable mspec $ A.Variable mspec nonceName)))
let newSpec = (A.Rep mrep (A.For mfor from (A.ExprVariable mspec $ A.Variable mspec nonceName) step))
modifyName n $ \nd -> nd { A.ndSpecType = newSpec }
return $ A.Spec mspec spec $
A.Spec m (A.Specification mspec n newSpec) scope

View File

@ -122,7 +122,7 @@ flattenAssign = pass "Flatten assignment"
-- inside.
do counter <- makeNonceCounter "i" m
let zero = A.Literal m A.Int $ A.IntLiteral m "0"
let rep = A.For m zero (A.SizeVariable m srcV)
let rep = A.For m zero (A.SizeVariable m srcV) (makeConstant m 1)
itemT <- trivialSubscriptType m t
-- Don't need to check bounds, as we'll always be within bounds
let sub = A.Subscript m A.NoCheck (A.ExprVariable m