Handle IsChannelArray when adding _sizes.
This also refactors the sizes-array-declaring code, pulling the declaration of static sizes out to a helper function, and does a couple of other minor cleanups to match.
This commit is contained in:
parent
ad875bd477
commit
04f72a62db
|
@ -183,32 +183,38 @@ declareSizesArray = occamOnlyPass "Declare array-size arrays"
|
||||||
= do t <- typeOfSpec spec
|
= do t <- typeOfSpec spec
|
||||||
case (spec, t) of
|
case (spec, t) of
|
||||||
(_, Just (A.Array ds elemT)) ->
|
(_, Just (A.Array ds elemT)) ->
|
||||||
do sizeSpec <- if elem A.UnknownDimension ds
|
do let n_sizes = append_sizes n
|
||||||
then
|
let defineStaticSizes ds
|
||||||
|
= do let st = makeStaticSizeSpec m' n_sizes ds
|
||||||
|
defineSizesName m' n_sizes st
|
||||||
|
return $ A.Specification m' n_sizes st
|
||||||
|
sizeSpec <-
|
||||||
|
if elem A.UnknownDimension ds
|
||||||
-- At least one unknown dimension:
|
-- At least one unknown dimension:
|
||||||
case spec of
|
then case spec of
|
||||||
-- TODO I think retyping a channel array ends up here, and probably isn't handled right
|
-- TODO I think retyping a channel array ends up
|
||||||
(A.Retypes _ _ _ v) -> retypesSizes m' (append_sizes n) ds elemT v
|
-- here, and probably isn't handled right
|
||||||
|
A.Retypes _ _ _ v ->
|
||||||
|
retypesSizes m' n_sizes ds elemT v
|
||||||
|
A.Is _ _ _ v ->
|
||||||
|
abbrevVarSizes m n_sizes ds v
|
||||||
|
A.IsChannelArray _ _ vs ->
|
||||||
|
defineStaticSizes [makeDimension m' (length vs)]
|
||||||
|
A.IsExpr _ _ _ (A.ExprVariable _ v) ->
|
||||||
|
abbrevVarSizes m n_sizes ds v
|
||||||
|
-- The dimensions in a literal should all be
|
||||||
|
-- static:
|
||||||
|
A.IsExpr _ _ _ (A.Literal _ (A.Array ds' _) _) ->
|
||||||
|
defineStaticSizes ds'
|
||||||
_ ->
|
_ ->
|
||||||
let n_sizes = append_sizes n in
|
dieP m $ "Could not handle unknown array spec: "
|
||||||
case spec of
|
++ pshow spec
|
||||||
A.Is _ _ _ v -> abbrevVarSizes m n_sizes ds v
|
|
||||||
A.IsExpr _ _ _ (A.ExprVariable _ v) -> abbrevVarSizes m n_sizes ds v
|
|
||||||
-- The dimensions in a literal should all be static:
|
|
||||||
A.IsExpr _ _ _ (A.Literal _ (A.Array ds _) _) ->
|
|
||||||
do let sizeSpecType = makeStaticSizeSpec m' n_sizes ds
|
|
||||||
defineSizesName m' n_sizes sizeSpecType
|
|
||||||
return $ A.Specification m' n_sizes sizeSpecType
|
|
||||||
_ -> dieP m $ "Could not handle unknown array spec: " ++ pshow spec
|
|
||||||
-- Everything is statically sized:
|
-- Everything is statically sized:
|
||||||
else do let n_sizes = append_sizes n
|
else defineStaticSizes ds
|
||||||
sizeSpecType = makeStaticSizeSpec m' n_sizes ds
|
|
||||||
sizeSpec = A.Specification m' n_sizes sizeSpecType
|
|
||||||
defineSizesName m' n_sizes sizeSpecType
|
|
||||||
return sizeSpec
|
|
||||||
return (A.Spec m sizeSpec $ A.Spec m sp $ s)
|
return (A.Spec m sizeSpec $ A.Spec m sp $ s)
|
||||||
(A.RecordType m _ fs, _) ->
|
(A.RecordType m _ fs, _) ->
|
||||||
do fieldDeclarations <- foldM (declareFieldSizes (A.nameName n) m) s fs
|
do fieldDeclarations <-
|
||||||
|
foldM (declareFieldSizes (A.nameName n) m) s fs
|
||||||
return $ A.Spec m sp fieldDeclarations
|
return $ A.Spec m sp fieldDeclarations
|
||||||
_ -> return str
|
_ -> return str
|
||||||
doStructured s = return s
|
doStructured s = return s
|
||||||
|
@ -279,7 +285,8 @@ addSizesActualParameters = occamOnlyPass "Add array-size arrays to PROC calls"
|
||||||
(applyDepthM doProcess)
|
(applyDepthM doProcess)
|
||||||
where
|
where
|
||||||
doProcess :: A.Process -> PassM A.Process
|
doProcess :: A.Process -> PassM A.Process
|
||||||
doProcess (A.ProcCall m n params) = concatMapM transformActual params >>* A.ProcCall m n
|
doProcess (A.ProcCall m n params)
|
||||||
|
= concatMapM transformActual params >>* A.ProcCall m n
|
||||||
doProcess p = return p
|
doProcess p = return p
|
||||||
|
|
||||||
transformActual :: A.Actual -> PassM [A.Actual]
|
transformActual :: A.Actual -> PassM [A.Actual]
|
||||||
|
@ -317,3 +324,4 @@ simplifySlices = occamOnlyPass "Simplify array slices"
|
||||||
A.UnknownDimension -> return $ A.SizeVariable m' v
|
A.UnknownDimension -> return $ A.SizeVariable m' v
|
||||||
return (A.SubscriptedVariable m (A.SubscriptFromFor m' check from (A.Dyadic m A.Subtr limit from)) v)
|
return (A.SubscriptedVariable m (A.SubscriptFromFor m' check from (A.Dyadic m A.Subtr limit from)) v)
|
||||||
doVariable v = return v
|
doVariable v = return v
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user