@@ -163,7 +163,7 @@ compileProc proc procID =
163163 gFlows = makeGlobalFlows (zip [0 .. ] params') $ procProtoResources proto
164164 let proto' = PrimProto (procProtoName proto) params' gFlows
165165 logClause $ " comparams : " ++ show params'
166- logClause $ " globalFlows: " ++ show gFlows
166+ logClause $ " globalFlows: " ++ show gFlows
167167 callSiteCount <- gets nextCallSiteID
168168 mSpec <- lift $ getModule modSpec
169169 let pSpec = ProcSpec mSpec procName procID Set. empty
@@ -287,6 +287,13 @@ compileSimpleStmt' call@(ProcCall func _ _ args) = do
287287 . trustFromJust (" untyped higher-order term " ++ show fn) . maybeExpType $ content fn
288288 fn' <- compileHigherFunc fn
289289 return $ PrimHigher callSiteID fn' impurity' args'
290+ compileSimpleStmt' (ForeignCall " lpvm" " sizeof" flags [arg, out]) = do
291+ repSize <- case content arg of
292+ Typed _ ty _ -> typeRepSize . trustFromJust " sizeof with unkown typerep" <$> lift (lookupTypeRepresentation ty)
293+ _ -> shouldnt $ " untyped in sizeof " ++ show arg
294+ [out'] <- placedApply compileArg out
295+ let size = if " bits" `elem` flags then repSize else (repSize + 7 ) `div` 8
296+ return $ PrimForeign " llvm" " move" [] [ArgInt (fromIntegral size) intType, out']
290297compileSimpleStmt' (ForeignCall lang name flags args) = do
291298 args' <- concat <$> mapM (placedApply compileArg) args
292299 return $ PrimForeign lang name flags args'
@@ -377,24 +384,24 @@ compileParam allFlows startVars endVars procName idx param@(Param name ty flow f
377384 (shouldnt (" compileParam for input param " ++ show param
378385 ++ " of proc " ++ show procName))
379386 name startVars
380- gFlows
381- | (isResourcefulHigherOrder ||| genericType) ty
387+ gFlows
388+ | (isResourcefulHigherOrder ||| genericType) ty
382389 = emptyGlobalFlows{globalFlowsParams= USet. singleton inIdx}
383390 | otherwise = emptyGlobalFlows
384391 ]
385- ++
392+ ++
386393 [PrimParam (PrimVarName name num) ty FlowOut ftype (ParamInfo False gFlows)
387394 | flowsOut flow
388395 , let num = Map. findWithDefault
389396 (shouldnt (" compileParam for output param " ++ show param
390397 ++ " of proc " ++ show procName))
391398 name endVars
392- gFlows
399+ gFlows
393400 | isResourcefulHigherOrder ty = univGlobalFlows
394401 | genericType ty = emptyGlobalFlows{globalFlowsParams= UniversalSet }
395402 | otherwise = emptyGlobalFlows
396403 ]
397- where
404+ where
398405 inIdx = idx
399406 outIdx = if flowsIn flow then idx + 1 else idx
400407
0 commit comments