Added more helper functions to the Pass module for constructing passes

This commit is contained in:
Neil Brown 2008-06-02 14:21:56 +00:00
parent 59e0922263
commit 6f6538ed57
2 changed files with 28 additions and 4 deletions

View File

@ -125,15 +125,40 @@ passOnlyOnAST name func x
Nothing -> dieP emptyMeta $ name ++ " crazy cast error at top-level" Nothing -> dieP emptyMeta $ name ++ " crazy cast error at top-level"
Just y' -> return y' Just y' -> return y'
rainOnlyPass :: String -> [Property] -> [Property] -> (forall t. Data t => t -> PassM t) -> Pass type PassMaker = String -> [Property] -> [Property] -> (forall t. Data t => t -> PassM t) -> Pass
rainOnlyPass name pre post code
passMakerHelper :: (CompState -> Bool) -> PassMaker
passMakerHelper f name pre post code
= Pass {passCode = code = Pass {passCode = code
,passName = name ,passName = name
,passPre = Set.fromList pre ,passPre = Set.fromList pre
,passPost = Set.fromList post ,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. -- | 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

View File

@ -19,7 +19,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
-- | Lists of passes -- | Lists of passes
module PassList (calculatePassList, getPassList) where module PassList (calculatePassList, getPassList) where
import Control.Monad.Error
import Control.Monad.State import Control.Monad.State
import Data.List import Data.List
import qualified Data.Map as Map import qualified Data.Map as Map