From c40d94c655a10349490325999204550135aff1b4 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 12 Sep 2007 08:50:19 +0000 Subject: [PATCH] Added a couple of passes that check the validity of the AST at the beginning and end of the Rain passes --- frontends/RainPasses.hs | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/frontends/RainPasses.hs b/frontends/RainPasses.hs index a9ad197..6870cd7 100644 --- a/frontends/RainPasses.hs +++ b/frontends/RainPasses.hs @@ -36,7 +36,8 @@ import TreeUtil -- | An ordered list of the Rain-specific passes to be run. rainPasses :: [(String,Pass)] rainPasses = - [ ("Resolve Int -> Int64",transformInt) + [ ("AST Validity check, Rain #1", excludeNonRainFeatures) + ,("Resolve Int -> Int64",transformInt) ,("Uniquify variable declarations, record declared types and resolve variable names",uniquifyAndResolveVars) --depends on transformInt ,("Record inferred name types in dictionary",recordInfNameTypes) --depends on uniquifyAndResolveVars ,("Find and tag the main function",findMain) --depends on uniquifyAndResolveVars @@ -49,6 +50,7 @@ rainPasses = --must be done after transformEachRange ,("Transform Rain functions into the occam form",transformFunction) --must be done after transformEach, depends on uniquifyAndResolveVars and recordInfNameTypes + ,("AST Validity check, Rain #2", (\x -> excludeNonRainFeatures x >>= excludeTransformedRainFeatures)) ] -- | A pass that transforms all instances of 'A.Int' into 'A.Int64' @@ -321,3 +323,41 @@ transformFunction = everywhereM (mkM transformFunction') _ -> dieP m "Functions must have a return statement as their last statement" _ -> dieP m "Functions must have seq[uential] bodies" transformFunction' s = return s + +-- | All the items that should have been removed at the end of the Rain passes. +excludeTransformedRainFeatures :: Data t => t -> PassM t +excludeTransformedRainFeatures = excludeConstr + [ con0 A.Int + ,con0 A.Any + ,con3 A.RangeConstr + ,con3 A.ForEach + ] + +-- | All the items that should not occur in an AST that comes from Rain (up until it goes into the shared passes). +excludeNonRainFeatures :: Data t => t -> PassM t +excludeNonRainFeatures = excludeConstr + [ con0 A.Real32 + ,con0 A.Real64 + ,con2 A.Counted + ,con0 A.Timer + ,con1 A.Port + ,con3 A.IntrinsicFunctionCall + ,con2 A.BytesInExpr + ,con2 A.BytesInType + ,con3 A.OffsetOf + ,con0 A.After + ,con3 A.InCounted + ,con3 A.OutCounted + ,con2 A.InputTimerRead + ,con2 A.InputTimerAfter + ,con2 A.Place + ,con3 A.IsChannelArray + ,con4 A.Retypes + ,con4 A.RetypesExpr + ,con0 A.PriPar + ,con0 A.PlacedPar + ,con1 A.Stop + ,con3 A.Processor + ,con3 A.IntrinsicProcCall + ] +