diff --git a/pass/Pass.hs b/pass/Pass.hs index ea6d110..b1e96b0 100644 --- a/pass/Pass.hs +++ b/pass/Pass.hs @@ -125,15 +125,40 @@ passOnlyOnAST name func x Nothing -> dieP emptyMeta $ name ++ " crazy cast error at top-level" Just y' -> return y' -rainOnlyPass :: String -> [Property] -> [Property] -> (forall t. Data t => t -> PassM t) -> Pass -rainOnlyPass name pre post code +type PassMaker = String -> [Property] -> [Property] -> (forall t. Data t => t -> PassM t) -> Pass + +passMakerHelper :: (CompState -> Bool) -> PassMaker +passMakerHelper f name pre post code = Pass {passCode = code ,passName = name ,passPre = Set.fromList pre ,passPost = Set.fromList post - ,passEnabled = (== FrontendRain) . csFrontend + ,passEnabled = f } +rainOnlyPass :: PassMaker +rainOnlyPass = passMakerHelper $ (== FrontendRain) . csFrontend + +occamOnlyPass :: PassMaker +occamOnlyPass = passMakerHelper $ (== FrontendOccam) . csFrontend + +cOnlyPass :: PassMaker +cOnlyPass = passMakerHelper $ (== BackendC) . csBackend + +cppOnlyPass :: PassMaker +cppOnlyPass = passMakerHelper $ (== BackendCPPCSP) . csBackend + + +pass :: String -> [Property] -> [Property] -> (forall t. Data t => t -> PassM t) -> Pass +pass name pre post code + = Pass {passCode = code + ,passName = name + ,passPre = Set.fromList pre + ,passPost = Set.fromList post + ,passEnabled = const True + } + + -- | Compose a list of passes into a single pass by running them in the order given. runPasses :: [Pass] -> (A.AST -> PassM A.AST) runPasses [] ast = return ast diff --git a/pass/PassList.hs b/pass/PassList.hs index 2ea3234..1b03c9e 100644 --- a/pass/PassList.hs +++ b/pass/PassList.hs @@ -19,7 +19,6 @@ with this program. If not, see . -- | Lists of passes module PassList (calculatePassList, getPassList) where -import Control.Monad.Error import Control.Monad.State import Data.List import qualified Data.Map as Map