Reintroduced the transformRangeRep pass, and fixed the transformEachRange pass (along with fixing the relevant tests)
This commit is contained in:
parent
41cca68e4e
commit
78606faaae
|
@ -51,6 +51,7 @@ rainPasses =
|
||||||
[ findMain
|
[ findMain
|
||||||
, transformEachRange
|
, transformEachRange
|
||||||
, pullUpForEach
|
, pullUpForEach
|
||||||
|
, transformRangeRep
|
||||||
, pullUpParDeclarations
|
, pullUpParDeclarations
|
||||||
, mobiliseLists
|
, mobiliseLists
|
||||||
, implicitMobility
|
, implicitMobility
|
||||||
|
@ -190,22 +191,33 @@ transformEachRange = rainOnlyPass "Convert seqeach/pareach loops over ranges int
|
||||||
(A.Rep repMeta -- Outer replicator
|
(A.Rep repMeta -- Outer replicator
|
||||||
(A.ForEach eachMeta -- goes through each itme
|
(A.ForEach eachMeta -- goes through each itme
|
||||||
(A.Literal _ _
|
(A.Literal _ _
|
||||||
(A.ArrayListLiteral _ -- in a list
|
(A.RangeLiteral _ begin end) -- a list made from a range
|
||||||
(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.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 }
|
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
|
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
|
-- TODO this is almost certainly better figured out from the CFG
|
||||||
checkFunction :: PassType
|
checkFunction :: PassType
|
||||||
checkFunction = return -- applyDepthM checkFunction'
|
checkFunction = return -- applyDepthM checkFunction'
|
||||||
|
|
|
@ -70,8 +70,8 @@ testEachRangePass0 :: Test
|
||||||
testEachRangePass0 = TestCase $ testPass "testEachRangePass0" exp transformEachRange orig (return ())
|
testEachRangePass0 = TestCase $ testPass "testEachRangePass0" exp transformEachRange orig (return ())
|
||||||
where
|
where
|
||||||
orig = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
|
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
|
$ A.Rep m (A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral m
|
||||||
undefined (intLiteral 0) (intLiteral 9)))))
|
(intLiteral 0) (intLiteral 9)))))
|
||||||
(A.Only m (makeSimpleAssign "c" "x"))
|
(A.Only m (makeSimpleAssign "c" "x"))
|
||||||
exp = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "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)))
|
$ 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 ())
|
testEachRangePass1 = TestCase $ testPass "testEachRangePass1" exp transformEachRange orig (return ())
|
||||||
where
|
where
|
||||||
orig = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "x")
|
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
|
$ A.Rep m (A.ForEach m (A.Literal m (A.List A.Int) (A.RangeLiteral
|
||||||
(intLiteral (-5)) (intLiteral (-2))))))
|
m (intLiteral (-5)) (intLiteral (-2))))))
|
||||||
(A.Only m (makeSimpleAssign "c" "x"))
|
(A.Only m (makeSimpleAssign "c" "x"))
|
||||||
exp = A.Par m A.PlainPar $ A.Spec m (A.Specification m (simpleName "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)
|
$ A.Rep m (A.For m (intLiteral (-5)) (makeRange (-5)
|
||||||
|
@ -93,7 +93,7 @@ testEachRangePass2 :: Test
|
||||||
testEachRangePass2 = TestCase $ testPass "testEachRangePass2" exp transformEachRange orig (return ())
|
testEachRangePass2 = TestCase $ testPass "testEachRangePass2" exp transformEachRange orig (return ())
|
||||||
where
|
where
|
||||||
orig = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
|
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)))))
|
(intLiteral 6) (intLiteral 6)))))
|
||||||
(A.Only m (makeSimpleAssign "c" "x"))
|
(A.Only m (makeSimpleAssign "c" "x"))
|
||||||
exp = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
|
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 ())
|
testEachRangePass3 = TestCase $ testPass "testEachRangePass3" exp transformEachRange orig (return ())
|
||||||
where
|
where
|
||||||
orig = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
|
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)))))
|
(intLiteral 6) (intLiteral 0)))))
|
||||||
(A.Only m (makeSimpleAssign "c" "x"))
|
(A.Only m (makeSimpleAssign "c" "x"))
|
||||||
exp = A.Seq m $ A.Spec m (A.Specification m (simpleName "x") $ A.Rep m
|
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 :: Test
|
||||||
testRangeRepPass0 = TestCase $ testPass "testRangeRepPass0" exp transformRangeRep orig (return())
|
testRangeRepPass0 = TestCase $ testPass "testRangeRepPass0" exp transformRangeRep orig (return())
|
||||||
where
|
where
|
||||||
orig = A.ExprConstr m $ A.RangeConstr m A.Byte (intLiteral 0) (intLiteral 1)
|
orig = A.Literal m (A.List A.Int) $ A.RangeLiteral m (intLiteral 0) (intLiteral 1)
|
||||||
exp = tag2 A.ExprConstr DontCare $ mRepConstr A.Byte ("repIndex"@@DontCare)
|
exp = mLiteral (A.List A.Int) $ mArrayListLiteral $ mSpecE
|
||||||
(mFor (intLiteral 0) (makeRange 0 1) (intLiteral 1))
|
(mSpecification ("repIndex"@@DontCare) (mRep $ mFor (intLiteral 0) (makeRange 0 1) (intLiteral 1)))
|
||||||
(tag2 A.ExprVariable DontCare $ tag2 A.Variable DontCare $ "repIndex"@@DontCare)
|
(mOnlyE $ mExprVariable $ mVariable $ "repIndex"@@DontCare)
|
||||||
|
|
||||||
--TODO consider/test pulling up the definitions of variables involved in return statements in functions
|
--TODO consider/test pulling up the definitions of variables involved in return statements in functions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user