Reintroduced the transformRangeRep pass, and fixed the transformEachRange pass (along with fixing the relevant tests)

This commit is contained in:
Neil Brown 2009-02-03 12:31:54 +00:00
parent 41cca68e4e
commit 78606faaae
2 changed files with 32 additions and 20 deletions

View File

@ -51,6 +51,7 @@ rainPasses =
[ findMain
, transformEachRange
, pullUpForEach
, transformRangeRep
, pullUpParDeclarations
, mobiliseLists
, implicitMobility
@ -190,22 +191,33 @@ transformEachRange = rainOnlyPass "Convert seqeach/pareach loops over ranges int
(A.Rep repMeta -- Outer replicator
(A.ForEach eachMeta -- goes through each itme
(A.Literal _ _
(A.ArrayListLiteral _ -- in a list
(A.Spec _
(A.Specification _ n r@(A.Rep {})) -- made from a replicator
(A.Only _ (A.ExprVariable _ (A.Variable _ n')))
-- where the inner expression is just the replicator
)
)
(A.RangeLiteral _ begin end) -- a list made from a range
)
)
)
) | A.nameName n' == A.nameName n
= do -- Need to change the stored abbreviation mode to original:
) = do -- Need to change the stored abbreviation mode to original:
modifyName loopVar $ \nd -> nd { A.ndAbbrevMode = A.Original }
return $ A.Specification mspec loopVar r
return $ A.Specification mspec loopVar $ A.Rep repMeta $
A.For eachMeta begin (addOne $ subExprs end begin) (makeConstant eachMeta 1)
doSpec s = return s
transformRangeRep :: Pass
transformRangeRep = rainOnlyPass "Convert simple Rain range constructors into more general array constructors"
(Prop.agg_typesDone ++ [Prop.eachRangeTransformed])
[Prop.rangeTransformed]
(applyDepthM doExpression)
where
doExpression :: A.Expression -> PassM A.Expression
doExpression (A.Literal m t (A.RangeLiteral m' begin end))
= do let count = addOne $ subExprs end begin
rep = A.Rep m' $ A.For m' begin count $ makeConstant m 1
spec@(A.Specification _ repN _) <- defineNonce m' "rep_constr"
rep A.ValAbbrev
return $ A.Literal m t $ A.ArrayListLiteral m' $
A.Spec m' spec $ A.Only m' $
(A.ExprVariable m' $ A.Variable m' repN)
doExpression e = return e
-- TODO this is almost certainly better figured out from the CFG
checkFunction :: PassType
checkFunction = return -- applyDepthM checkFunction'

View File

@ -70,8 +70,8 @@ testEachRangePass0 :: Test
testEachRangePass0 = TestCase $ testPass "testEachRangePass0" exp transformEachRange orig (return ())
where
orig = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
$ A.Rep m (A.ForEach m (A.ExprConstr m (A.RangeConstr m
undefined (intLiteral 0) (intLiteral 9)))))
$ A.Rep m (A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral m
(intLiteral 0) (intLiteral 9)))))
(A.Only m (makeSimpleAssign "c" "x"))
exp = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
$ A.Rep m (A.For m (intLiteral 0) (makeRange 0 9) (intLiteral 1)))
@ -81,8 +81,8 @@ testEachRangePass1 :: Test
testEachRangePass1 = TestCase $ testPass "testEachRangePass1" exp transformEachRange orig (return ())
where
orig = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
$ A.Rep m (A.ForEach m (A.ExprConstr m (A.RangeConstr m undefined
(intLiteral (-5)) (intLiteral (-2))))))
$ A.Rep m (A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral
m (intLiteral (-5)) (intLiteral (-2))))))
(A.Only m (makeSimpleAssign "c" "x"))
exp = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
$ A.Rep m (A.For m (intLiteral (-5)) (makeRange (-5)
@ -93,7 +93,7 @@ testEachRangePass2 :: Test
testEachRangePass2 = TestCase $ testPass "testEachRangePass2" exp transformEachRange orig (return ())
where
orig = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
(A.ForEach m (A.ExprConstr m (A.RangeConstr m undefined
(A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral m
(intLiteral 6) (intLiteral 6)))))
(A.Only m (makeSimpleAssign "c" "x"))
exp = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
@ -104,7 +104,7 @@ testEachRangePass3 :: Test
testEachRangePass3 = TestCase $ testPass "testEachRangePass3" exp transformEachRange orig (return ())
where
orig = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
(A.ForEach m (A.ExprConstr m (A.RangeConstr m undefined
(A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral m
(intLiteral 6) (intLiteral 0)))))
(A.Only m (makeSimpleAssign "c" "x"))
exp = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
@ -355,10 +355,10 @@ testParamPass8 = TestList [TestCase $ testPassShouldFail "testParamPass8/process
testRangeRepPass0 :: Test
testRangeRepPass0 = TestCase $ testPass "testRangeRepPass0" exp transformRangeRep orig (return())
where
orig = A.ExprConstr m $ A.RangeConstr m A.Byte (intLiteral 0) (intLiteral 1)
exp = tag2 A.ExprConstr DontCare $ mRepConstr A.Byte ("repIndex"@@DontCare)
(mFor (intLiteral 0) (makeRange 0 1) (intLiteral 1))
(tag2 A.ExprVariable DontCare $ tag2 A.Variable DontCare $ "repIndex"@@DontCare)
orig = A.Literal m (A.List A.Int) $ A.RangeLiteral m (intLiteral 0) (intLiteral 1)
exp = mLiteral (A.List A.Int) $ mArrayListLiteral $ mSpecE
(mSpecification ("repIndex"@@DontCare) (mRep $ mFor (intLiteral 0) (makeRange 0 1) (intLiteral 1)))
(mOnlyE $ mExprVariable $ mVariable $ "repIndex"@@DontCare)
--TODO consider/test pulling up the definitions of variables involved in return statements in functions