From: Christiaan Baaij Date: Tue, 23 Jun 2009 13:10:21 +0000 (+0200) Subject: Merge branch 'cλash' of http://git.stderr.nl/matthijs/projects/master-project X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=b4ae262efb842ce254721f0f9ed9f0936241e094;hp=aa03222c571e37a1a05b6fbf4e09c748cf786286;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Merge branch 'cλash' of git.stderr.nl/matthijs/projects/master-project * 'cλash' of http://git.stderr.nl/matthijs/projects/master-project: Ignore cast expressions when generating VHDL. Add Cast propagation transform. Make subeverywhere support Cast expressions. Remove a double line introduced a few commits back. Make subeverywhere complain for unknown expressions. --- diff --git a/Normalize.hs b/Normalize.hs index cceefc0..747a95b 100644 --- a/Normalize.hs +++ b/Normalize.hs @@ -43,7 +43,6 @@ import Pretty -- η abstraction -------------------------------- eta, etatop :: Transform -eta expr | is_fun expr && not (is_lam expr) = do eta expr | is_fun expr && not (is_lam expr) = do let arg_ty = (fst . Type.splitFunTy . CoreUtils.exprType) expr id <- mkInternalVar "param" arg_ty @@ -70,6 +69,20 @@ beta expr = return expr -- Perform this transform everywhere betatop = everywhere ("beta", beta) +-------------------------------- +-- Cast propagation +-------------------------------- +-- Try to move casts as much downward as possible. +castprop, castproptop :: Transform +castprop (Cast (Let binds expr) ty) = change $ Let binds (Cast expr ty) +castprop expr@(Cast (Case scrut b _ alts) ty) = change (Case scrut b ty alts') + where + alts' = map (\(con, bndrs, expr) -> (con, bndrs, (Cast expr ty))) alts +-- Leave all other expressions unchanged +castprop expr = return expr +-- Perform this transform everywhere +castproptop = everywhere ("castprop", castprop) + -------------------------------- -- let recursification -------------------------------- @@ -408,7 +421,7 @@ funproptop = everywhere ("funprop", funprop) -- What transforms to run? -transforms = [typeproptop, funproptop, etatop, betatop, letremovetop, letrectop, letsimpltop, letflattop, casewildtop, scrutsimpltop, casevalsimpltop, caseremovetop, inlinefuntop, appsimpltop] +transforms = [typeproptop, funproptop, etatop, betatop, castproptop, letremovetop, letrectop, letsimpltop, letflattop, casewildtop, scrutsimpltop, casevalsimpltop, caseremovetop, inlinefuntop, appsimpltop] -- Turns the given bind into VHDL normalizeModule :: diff --git a/NormalizeTools.hs b/NormalizeTools.hs index 400bf88..8e57ba8 100644 --- a/NormalizeTools.hs +++ b/NormalizeTools.hs @@ -142,9 +142,16 @@ subeverywhere trans (Case scrut b t alts) = do transalt (con, binders, expr) = do expr' <- trans expr return (con, binders, expr') - -subeverywhere trans expr = return expr +subeverywhere trans (Var x) = return $ Var x +subeverywhere trans (Lit x) = return $ Lit x +subeverywhere trans (Type x) = return $ Type x + +subeverywhere trans (Cast expr ty) = do + expr' <- trans expr + return $ Cast expr' ty + +subeverywhere trans expr = error $ "NormalizeTools.subeverywhere Unsupported expression: " ++ show expr -- Apply the given transformation to all expressions, except for direct -- arguments of an application diff --git a/VHDL.hs b/VHDL.hs index 24c4eb0..99aa089 100644 --- a/VHDL.hs +++ b/VHDL.hs @@ -264,6 +264,11 @@ mkConcSm :: (CoreSyn.CoreBndr, CoreSyn.CoreExpr) -- ^ The binding to process -> VHDLState [AST.ConcSm] -- ^ The corresponding VHDL component instantiations. + +-- Ignore Cast expressions, they should not longer have any meaning as long as +-- the type works out. +mkConcSm (bndr, Cast expr ty) = mkConcSm (bndr, expr) + mkConcSm (bndr, app@(CoreSyn.App _ _))= do let (CoreSyn.Var f, args) = CoreSyn.collectArgs app let valargs' = filter isValArg args