Make genBytesIn work on arrays with unknown dimensions
This commit is contained in:
parent
164aa15ad3
commit
43e36f11d0
|
@ -147,18 +147,24 @@ genType t
|
||||||
Just s -> tell [s]
|
Just s -> tell [s]
|
||||||
Nothing -> missing $ "genType " ++ show t
|
Nothing -> missing $ "genType " ++ show t
|
||||||
|
|
||||||
genBytesInType :: A.Type -> CGen ()
|
genBytesIn :: A.Type -> Maybe A.Variable -> CGen ()
|
||||||
genBytesInType (A.Array ds t) = genBytesInDims ds >> genBytesInType t
|
genBytesIn (A.Array ds t) v = genBytesInArray ds 0 >> genBytesIn t v
|
||||||
where
|
where
|
||||||
genBytesInDims [] = return ()
|
genBytesInArray [] _ = return ()
|
||||||
genBytesInDims ((A.Dimension n):ds)
|
genBytesInArray ((A.Dimension n):ds) i
|
||||||
= genBytesInDims ds >> tell [show n, " * "]
|
= do genBytesInArray ds (i + 1)
|
||||||
genBytesInDims _ = missing "genBytesInType with empty dimension"
|
tell [show n, " * "]
|
||||||
--bytesInType (A.UserDataType n)
|
genBytesInArray (A.UnknownDimension:ds) i
|
||||||
genBytesInType t
|
= case v of
|
||||||
|
Just rv ->
|
||||||
|
do genBytesInArray ds (i + 1)
|
||||||
|
genVariable rv
|
||||||
|
tell ["_sizes[", show i, "] * "]
|
||||||
|
Nothing -> missing "genBytesIn array type with unknown dimension"
|
||||||
|
genBytesIn t _
|
||||||
= case scalarType t of
|
= case scalarType t of
|
||||||
Just s -> tell ["sizeof (", s, ")"]
|
Just s -> tell ["sizeof (", s, ")"]
|
||||||
Nothing -> missing $ "genBytesInType " ++ show t
|
Nothing -> missing $ "genBytesIn " ++ show t
|
||||||
--}}}
|
--}}}
|
||||||
|
|
||||||
--{{{ declarations
|
--{{{ declarations
|
||||||
|
@ -465,7 +471,7 @@ genExpression (A.False m) = tell ["false"]
|
||||||
genExpression (A.IntrinsicFunctionCall m s es) = genIntrinsicFunction m s es
|
genExpression (A.IntrinsicFunctionCall m s es) = genIntrinsicFunction m s es
|
||||||
--genExpression (A.SubscriptedExpr m s e)
|
--genExpression (A.SubscriptedExpr m s e)
|
||||||
--genExpression (A.BytesInExpr m e)
|
--genExpression (A.BytesInExpr m e)
|
||||||
genExpression (A.BytesInType m t) = genBytesInType t
|
genExpression (A.BytesInType m t) = genBytesIn t Nothing
|
||||||
--genExpression (A.OffsetOf m t n)
|
--genExpression (A.OffsetOf m t n)
|
||||||
genExpression t = missing $ "genExpression " ++ show t
|
genExpression t = missing $ "genExpression " ++ show t
|
||||||
|
|
||||||
|
@ -552,7 +558,7 @@ genInputItem c (A.InCounted m cv av)
|
||||||
subT <- trivialSubscriptType t
|
subT <- trivialSubscriptType t
|
||||||
genVariable cv
|
genVariable cv
|
||||||
tell [" * "]
|
tell [" * "]
|
||||||
genBytesInType subT
|
genBytesIn subT (Just av)
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
genInputItem c (A.InVariable m v)
|
genInputItem c (A.InVariable m v)
|
||||||
= do t <- typeOfVariable v
|
= do t <- typeOfVariable v
|
||||||
|
@ -570,7 +576,7 @@ genInputItem c (A.InVariable m v)
|
||||||
tell [", "]
|
tell [", "]
|
||||||
rhs
|
rhs
|
||||||
tell [", "]
|
tell [", "]
|
||||||
genBytesInType t
|
genBytesIn t (Just v)
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
|
|
||||||
genOutputItem :: A.Variable -> A.OutputItem -> CGen ()
|
genOutputItem :: A.Variable -> A.OutputItem -> CGen ()
|
||||||
|
@ -587,7 +593,7 @@ genOutputItem c (A.OutCounted m ce ae)
|
||||||
subT <- trivialSubscriptType t
|
subT <- trivialSubscriptType t
|
||||||
genExpression ce
|
genExpression ce
|
||||||
tell [" * "]
|
tell [" * "]
|
||||||
genBytesInType subT
|
genBytesIn subT (Just v)
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
genOutputItem c (A.OutExpression m e)
|
genOutputItem c (A.OutExpression m e)
|
||||||
= do t <- typeOfExpression e
|
= do t <- typeOfExpression e
|
||||||
|
@ -604,7 +610,7 @@ genOutputItem c (A.OutExpression m e)
|
||||||
tell [", "]
|
tell [", "]
|
||||||
fst $ abbrevVariable A.Abbrev t v
|
fst $ abbrevVariable A.Abbrev t v
|
||||||
tell [", "]
|
tell [", "]
|
||||||
genBytesInType t
|
genBytesIn t (Just v)
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
_ ->
|
_ ->
|
||||||
do n <- makeNonce "output_item"
|
do n <- makeNonce "output_item"
|
||||||
|
@ -616,7 +622,7 @@ genOutputItem c (A.OutExpression m e)
|
||||||
tell ["ChanOut ("]
|
tell ["ChanOut ("]
|
||||||
genVariable c
|
genVariable c
|
||||||
tell [", &", n, ", "]
|
tell [", &", n, ", "]
|
||||||
genBytesInType t
|
genBytesIn t Nothing
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
--}}}
|
--}}}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,11 @@ PLACE should work.
|
||||||
|
|
||||||
Array comparisons generate silly code (rather than failing).
|
Array comparisons generate silly code (rather than failing).
|
||||||
|
|
||||||
|
Pullups don't work properly for this at the moment, because index changes after
|
||||||
|
the pullup:
|
||||||
|
c ? index; [array FROM index]
|
||||||
|
(Tested in cgtest12.)
|
||||||
|
|
||||||
## Long-term
|
## Long-term
|
||||||
|
|
||||||
If we have constant folding, we're three-quarters of the way towards having an
|
If we have constant folding, we're three-quarters of the way towards having an
|
||||||
|
|
Loading…
Reference in New Issue
Block a user