diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 421c12b..a28e5a8 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -2178,11 +2178,20 @@ cgenAllocMobile :: Meta -> A.Type -> Maybe A.Expression -> CGen() cgenAllocMobile m (A.Mobile t@(A.Array ds innerT)) Nothing | A.UnknownDimension `elem` ds = dieP m "Cannot allocate mobile array with unknown dimension" | otherwise = - do tell ["MTAllocDataArray(wptr,"] - call genBytesIn m innerT (Left False) - tell [",", show $ length ds] - prefixComma $ [call genExpression e | A.Dimension e <- ds] - tell [")"] + do let elemSize = call genBytesIn m innerT (Left False) + numDims = show $ length ds + wrap alloc = do tell ["TockZeroMobileArray("] + alloc + tell [","] + elemSize + tell [",", numDims, ")"] + mobInner <- isMobileType innerT + (if mobInner then wrap else id) $ do + tell ["MTAllocDataArray(wptr,"] + elemSize + tell [",", numDims] + prefixComma $ [call genExpression e | A.Dimension e <- ds] + tell [")"] cgenAllocMobile m (A.Mobile t) Nothing = do tell ["MTAlloc(wptr,"] mobileElemType False t diff --git a/support/tock_support_cif.h b/support/tock_support_cif.h index 15209ae..2f543dd 100644 --- a/support/tock_support_cif.h +++ b/support/tock_support_cif.h @@ -86,10 +86,21 @@ static inline void occam_RESIZE_MOBILE_ARRAY_1D (Workspace wptr, const int eleme //}}} //{{{ other mobile stuff +static inline void* TockMTLock(Workspace wptr, void* ptr, int lock) occam_unused; static inline void* TockMTLock(Workspace wptr, void* ptr, int lock) { MTLock(wptr, ptr, lock); return ptr; } + +static inline mt_array_t* TockZeroMobileArray(mt_array_t* arr, int elem_size, int num_dims) occam_unused; +static inline mt_array_t* TockZeroMobileArray(mt_array_t* arr, int elem_size, int num_dims) { + int total_size = elem_size; + for (int i = 0; i < num_dims; i++) { + total_size *= arr->dimensions[i]; + } + memset(arr->data, 0, total_size); + return arr; +} //}}} //{{{ top-level process interface