Added a pass to remove unneeded directions, i.e. c! where c is already an output end

This commit is contained in:
Neil Brown 2009-01-20 17:36:40 +00:00
parent c6959ac854
commit cc70438c1b

View File

@ -30,6 +30,7 @@ import Metadata
import Pass
import PrettyShow
import qualified Properties as Prop
import ShowCode
import Traversal
import Types
import Utils
@ -37,6 +38,7 @@ import Utils
squashArrays :: [Pass]
squashArrays =
[ removeDirections
, removeUnneededDirections
, simplifySlices
, declareSizesArray
, addSizesFormalParameters
@ -60,6 +62,32 @@ removeDirections
doVariable (A.DirectedVariable _ _ v) = v
doVariable v = v
-- | Remove variable directions that are superfluous. This prevents confusing
-- later passes, where the user has written something like:
-- []CHAN INT da! IS ...:
-- foo(da!)
--
-- The second direction specifier is unneeded, and will confuse passes such as
-- those adding sizes parameters (which looks for plain variables, since directed
-- arrays should already have been pulled up).
removeUnneededDirections :: Pass
removeUnneededDirections
= occamOnlyPass "Remove unneeded variable directions"
prereq
[]
(applyDepthM doVariable)
where
doVariable :: Transform (A.Variable)
doVariable whole@(A.DirectedVariable m dir v)
= do t <- astTypeOf v
case t of
A.Chan {} -> return whole
A.Array _ (A.Chan {}) -> return whole
A.ChanEnd chanDir _ _ | dir == chanDir -> return v
A.Array _ (A.ChanEnd chanDir _ _) | dir == chanDir -> return v
_ -> diePC m $ formatCode "Direction applied to non-channel type: %" t
doVariable v = return v
transformWaitFor :: Pass
transformWaitFor = cOnlyPass "Transform wait for guards into wait until guards"
[]