From 65550b705e9173a13a49731efce4045d7de649a3 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 20 Mar 2009 11:31:14 +0000 Subject: [PATCH] Added an AllSizesVariable item to the AST so that the backend inserts the right code for mobiles and non-mobiles --- backends/BackendPasses.hs | 4 ++-- backends/GenerateC.hs | 14 ++++++++++++++ common/ShowCode.hs | 3 ++- data/AST.hs | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/backends/BackendPasses.hs b/backends/BackendPasses.hs index 09545be..9815a08 100644 --- a/backends/BackendPasses.hs +++ b/backends/BackendPasses.hs @@ -384,10 +384,10 @@ addSizesActualParameters = occamOnlyPass "Add array-size arrays to PROC calls" = do t <- astTypeOf v case t of A.Array ds _ -> - return [a, A.ActualVariable $ sizes v] + return [a, A.ActualExpression $ sizes v] _ -> return [a] where - sizes (A.Variable m n) = A.Variable m (append_sizes n) + sizes v@(A.Variable m _) = A.AllSizesVariable m v sizes (A.DerefVariable _ v) = sizes v sizes (A.DirectedVariable _ _ v) = sizes v sizes (A.SubscriptedVariable _ _ v) = sizes v diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 1860487..1c06bd5 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -936,6 +936,20 @@ cgenExpression (A.SizeVariable m v) call genSizeSuffix (show n) A.List _ -> call genListSize v +cgenExpression e@(A.AllSizesVariable m v) + = case v of + A.SubscriptedVariable {} -> call genMissing $ "genExpression" ++ show e + A.DirectedVariable _ _ v' -> call genExpression $ A.AllSizesVariable m v' + A.DerefVariable _ v' -> do call genVariable v' + tell ["->dimensions"] + A.Variable _ n -> do t <- astTypeOf v + case t of + A.Array {} -> do call genVariable v + tell ["_sizes"] + A.Mobile (A.Array {}) + -> do call genVariable v + tell ["->dimensions"] + _ -> call genMissing $ "genExpression" ++ show e cgenExpression (A.Conversion m cm t e) = call genConversion m cm t e cgenExpression (A.ExprVariable m v) = call genVariable v cgenExpression (A.Literal _ t lr) = call genLiteral lr t diff --git a/common/ShowCode.hs b/common/ShowCode.hs index a588d7a..11e9bd2 100644 --- a/common/ShowCode.hs +++ b/common/ShowCode.hs @@ -415,6 +415,7 @@ instance ShowOccam A.Expression where showOccamM (A.SizeType _ t) = bracket $ tell ["SIZE "] >> showOccamM t showOccamM (A.SizeExpr _ e) = bracket $ tell ["SIZE "] >> showOccamM e showOccamM (A.SizeVariable _ v) = bracket $ tell ["SIZE "] >> showOccamM v + showOccamM (A.AllSizesVariable _ v) = bracket $ tell ["SIZES "] >> showOccamM v showOccamM (A.Conversion _ cm t e) = bracket $ showOccamM t >> convOrSpace cm >> showOccamM e showOccamM (A.ExprVariable _ v) = showOccamM v showOccamM (A.Literal _ _ lit) = showOccamM lit @@ -427,7 +428,7 @@ instance ShowOccam A.Expression where showOccamM (A.BytesInType _ t) = bracket $ tell ["BYTESIN "] >> showOccamM t showOccamM (A.OffsetOf _ t n) = tell ["OFFSETOF("] >> showOccamM t >> tell [" , "] >> showName n >> tell [")"] showOccamM (A.AllocMobile _ t me) = showOccamM t >> maybe (return ()) showOccamM me - + showOccamM (A.CloneMobile _ e) = tell["CLONE "] >> showOccamM e instance ShowRain A.Expression where showRainM (A.Monadic _ op e) = bracket $ showRainM op >> space >> showRainM e diff --git a/data/AST.hs b/data/AST.hs index 0049512..7bfd0ac 100644 --- a/data/AST.hs +++ b/data/AST.hs @@ -263,6 +263,9 @@ data Expression = -- | The size of the outermost dimension of an array variable (see -- 'SizeExpr'). | SizeVariable Meta Variable + -- | An array that contains all the dimensions of an array. Hence this is different + -- from SizeVariable which is only the outermost dimension. + | AllSizesVariable Meta Variable | Conversion Meta ConversionMode Type Expression | ExprVariable Meta Variable | Literal Meta Type LiteralRepr