Fixed the Rain passes so that the order correctly satisfies the pre-requisites
This commit is contained in:
parent
4537cd205c
commit
9f411bfd45
|
@ -31,6 +31,7 @@ import Errors
|
||||||
import Pass
|
import Pass
|
||||||
import qualified Properties as Prop
|
import qualified Properties as Prop
|
||||||
import RainTypes
|
import RainTypes
|
||||||
|
import SimplifyTypes
|
||||||
import TreeUtils
|
import TreeUtils
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
|
@ -38,22 +39,24 @@ import Types
|
||||||
|
|
||||||
-- | An ordered list of the Rain-specific passes to be run.
|
-- | An ordered list of the Rain-specific passes to be run.
|
||||||
rainPasses :: [Pass]
|
rainPasses :: [Pass]
|
||||||
rainPasses = makePassesDep' ((== FrontendRain) . csFrontend)
|
rainPasses = let f = makePassesDep' ((== FrontendRain) . csFrontend) in f
|
||||||
[ ("AST Validity check, Rain #1", excludeNonRainFeatures, [], []) -- TODO work out some dependencies
|
[ ("AST Validity check, Rain #1", excludeNonRainFeatures, [], []) -- TODO work out some dependencies
|
||||||
,("Dummy Rain pass", return, [], [Prop.retypesChecked])
|
,("Dummy Rain pass", return, [], [Prop.retypesChecked])
|
||||||
,("Resolve Int -> Int64", transformInt, [], [Prop.noInt])
|
,("Resolve Int -> Int64", transformInt, [], [Prop.noInt])
|
||||||
,("Uniquify variable declarations, record declared types and resolve variable names",
|
,("Uniquify variable declarations, record declared types and resolve variable names",
|
||||||
uniquifyAndResolveVars, [Prop.noInt], Prop.agg_namesDone \\ [Prop.inferredTypesRecorded])
|
uniquifyAndResolveVars, [Prop.noInt], Prop.agg_namesDone \\ [Prop.inferredTypesRecorded])
|
||||||
|
|
||||||
,("Fold all constant expressions", constantFoldPass, [Prop.noInt] ++ Prop.agg_namesDone
|
|
||||||
++ Prop.agg_typesDone, [Prop.constantsFolded, Prop.constantsChecked])
|
|
||||||
,("Rain Type Checking", performTypeUnification, [Prop.noInt] ++ Prop.agg_namesDone,
|
|
||||||
Prop.agg_typesDone)
|
|
||||||
|
|
||||||
,("Record inferred name types in dictionary", recordInfNameTypes,
|
,("Record inferred name types in dictionary", recordInfNameTypes,
|
||||||
Prop.agg_namesDone \\ [Prop.inferredTypesRecorded], [Prop.inferredTypesRecorded])
|
Prop.agg_namesDone \\ [Prop.inferredTypesRecorded], [Prop.inferredTypesRecorded])
|
||||||
|
|
||||||
|
,("Rain Type Checking", performTypeUnification, [Prop.noInt] ++ Prop.agg_namesDone,
|
||||||
|
[Prop.expressionTypesChecked, Prop.functionTypesChecked, Prop.processTypesChecked,
|
||||||
|
Prop.retypesChecked])
|
||||||
|
,("Fold all constant expressions", constantFoldPass, [Prop.noInt] ++ Prop.agg_namesDone
|
||||||
|
++ [Prop.inferredTypesRecorded], [Prop.constantsFolded, Prop.constantsChecked])
|
||||||
|
|
||||||
|
] ++ enablePassesWhen ((== FrontendRain) . csFrontend) simplifyTypes ++ f [
|
||||||
|
|
||||||
,("Find and tag the main function", findMain, Prop.agg_namesDone, [Prop.mainTagged])
|
("Find and tag the main function", findMain, Prop.agg_namesDone, [Prop.mainTagged])
|
||||||
,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",
|
,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",
|
||||||
transformEachRange, Prop.agg_typesDone ++ [Prop.constantsFolded], [Prop.eachRangeTransformed])
|
transformEachRange, Prop.agg_typesDone ++ [Prop.constantsFolded], [Prop.eachRangeTransformed])
|
||||||
,("Pull up foreach-expressions", pullUpForEach,
|
,("Pull up foreach-expressions", pullUpForEach,
|
||||||
|
|
|
@ -105,6 +105,10 @@ makePassesDep = map (\(s, p, pre, post) -> Pass p s (Set.fromList pre) (Set.from
|
||||||
makePassesDep' :: (CompState -> Bool) -> [(String, A.AST -> PassM A.AST, [Property], [Property])] -> [Pass]
|
makePassesDep' :: (CompState -> Bool) -> [(String, A.AST -> PassM A.AST, [Property], [Property])] -> [Pass]
|
||||||
makePassesDep' f = map (\(s, p, pre, post) -> Pass p s (Set.fromList pre) (Set.fromList post) f)
|
makePassesDep' f = map (\(s, p, pre, post) -> Pass p s (Set.fromList pre) (Set.fromList post) f)
|
||||||
|
|
||||||
|
enablePassesWhen :: (CompState -> Bool) -> [Pass] -> [Pass]
|
||||||
|
enablePassesWhen f = map (\p -> p
|
||||||
|
{passEnabled = \c -> f c && (passEnabled p c)})
|
||||||
|
|
||||||
-- | Compose a list of passes into a single pass by running them in the order given.
|
-- | Compose a list of passes into a single pass by running them in the order given.
|
||||||
runPasses :: [Pass] -> (A.AST -> PassM A.AST)
|
runPasses :: [Pass] -> (A.AST -> PassM A.AST)
|
||||||
runPasses [] ast = return ast
|
runPasses [] ast = return ast
|
||||||
|
|
|
@ -43,7 +43,8 @@ import Utils
|
||||||
|
|
||||||
commonPasses :: CompState -> [Pass]
|
commonPasses :: CompState -> [Pass]
|
||||||
commonPasses opts = concat $
|
commonPasses opts = concat $
|
||||||
[ simplifyTypes
|
-- Rain does simplifyTypes separately:
|
||||||
|
[ enablePassesWhen ((== FrontendOccam) . csFrontend) simplifyTypes
|
||||||
, makePassesDep' csUsageChecking [("Usage checking", runPassR usageCheckPass, Prop.agg_namesDone, [Prop.parUsageChecked])]
|
, makePassesDep' csUsageChecking [("Usage checking", runPassR usageCheckPass, Prop.agg_namesDone, [Prop.parUsageChecked])]
|
||||||
-- If usage checking is turned off, the pass list will break unless we insert this dummy item:
|
-- If usage checking is turned off, the pass list will break unless we insert this dummy item:
|
||||||
, makePassesDep' (not . csUsageChecking) [("Usage checking turned OFF", return, Prop.agg_namesDone, [Prop.parUsageChecked])]
|
, makePassesDep' (not . csUsageChecking) [("Usage checking turned OFF", return, Prop.agg_namesDone, [Prop.parUsageChecked])]
|
||||||
|
@ -86,8 +87,9 @@ checkList passes = case check [] passes of
|
||||||
check :: [Pass] -> [Pass] -> Either String [Pass]
|
check :: [Pass] -> [Pass] -> Either String [Pass]
|
||||||
check prev [] = Right prev
|
check prev [] = Right prev
|
||||||
check prev (p:ps)
|
check prev (p:ps)
|
||||||
= case filter givesPrereq ps of
|
= case filter givesPrereq (p:ps) of
|
||||||
-- Check that our pre-requisites are not supplied by a later pass:
|
-- Check that our pre-requisites are not supplied by a later pass
|
||||||
|
-- or supplied by the pass that needs them:
|
||||||
(x:_) ->
|
(x:_) ->
|
||||||
Left $ "Pass order not correct; one of the pre-requisites"
|
Left $ "Pass order not correct; one of the pre-requisites"
|
||||||
++ " for pass: " ++ (passName p) ++ " is supplied in a later"
|
++ " for pass: " ++ (passName p) ++ " is supplied in a later"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user