@@ -363,10 +363,10 @@ mkNetDecl (id_,tm) = preserveVarEnv $ do
363363 go pInfo (BlackBox {resultInits= nmDs, multiResult= True }) = withTicks ticks $ \ _ -> do
364364 tcm <- Lens. view tcCache
365365 let (args1, res) = splitMultiPrimArgs (multiPrimInfo' tcm pInfo) args0
366- (bbCtx, _) <- mkBlackBoxContext (primName pInfo) res args1
366+ (bbCtx, _) <- mkBlackBoxContext (primName pInfo) Concurrent res args1
367367 mapM (go' (primName pInfo) bbCtx) nmDs
368368 go pInfo (BlackBox {resultInits= nmDs}) = withTicks ticks $ \ _ -> do
369- (bbCtx, _) <- mkBlackBoxContext (primName pInfo) [i] args0
369+ (bbCtx, _) <- mkBlackBoxContext (primName pInfo) Concurrent [i] args0
370370 mapM (go' (primName pInfo) bbCtx) nmDs
371371 go _ _ = pure []
372372
@@ -413,8 +413,8 @@ mkDeclarations'
413413 -> Term
414414 -- ^ RHS of the let-binder
415415 -> NetlistMonad [Declaration ]
416- mkDeclarations' _declType bndr (collectTicks -> (Var v,ticks)) =
417- withTicks ticks (mkFunApp (Id. unsafeFromCoreId bndr) v [] )
416+ mkDeclarations' declType bndr (collectTicks -> (Var v,ticks)) =
417+ withTicks ticks (mkFunApp declType (Id. unsafeFromCoreId bndr) v [] )
418418
419419mkDeclarations' _declType _bndr e@ (collectTicks -> (Case _ _ [] ,_)) = do
420420 (_,sp) <- Lens. use curCompNm
@@ -436,7 +436,7 @@ mkDeclarations' declType bndr app = do
436436 case appF of
437437 Var f
438438 | null tyArgs ->
439- withTicks ticks (mkFunApp (Id. unsafeFromCoreId bndr) f args)
439+ withTicks ticks (mkFunApp declType (Id. unsafeFromCoreId bndr) f args)
440440 | otherwise -> do
441441 (_,sp) <- Lens. use curCompNm
442442 throw (ClashException sp ($ (curLoc) ++ " Not in normal form: Var-application with Type arguments:\n\n " ++ showPpr app) Nothing )
@@ -633,12 +633,13 @@ patPos reprs pat@(DataPat dataCon _ _) =
633633-- | Generate a list of Declarations for a let-binder where the RHS is a function application
634634mkFunApp
635635 :: HasCallStack
636- => Identifier -- ^ LHS of the let-binder
636+ => DeclarationType
637+ -> Identifier -- ^ LHS of the let-binder
637638 -> Id -- ^ Name of the applied function
638639 -> [Term ] -- ^ Function arguments
639640 -> [Declaration ] -- ^ Tick declarations
640641 -> NetlistMonad [Declaration ]
641- mkFunApp dstId fun args tickDecls = do
642+ mkFunApp declType dstId fun args tickDecls = do
642643 topAnns <- Lens. use topEntityAnns
643644 tcm <- Lens. view tcCache
644645 case (isGlobalId fun, lookupVarEnv fun topAnns) of
@@ -652,7 +653,7 @@ mkFunApp dstId fun args tickDecls = do
652653 -> do
653654 argHWTys <- mapM (unsafeCoreTypeToHWTypeM' $ (curLoc)) fArgTys1
654655 (argExprs, concat -> argDecls) <- unzip <$>
655- mapM (\ (e,t) -> mkExpr False Concurrent (NetlistId dstId t) e)
656+ mapM (\ (e,t) -> mkExpr False declType (NetlistId dstId t) e)
656657 (zip args fArgTys1)
657658
658659 -- Filter void arguments, but make sure to render their declarations:
@@ -724,7 +725,7 @@ mkFunApp dstId fun args tickDecls = do
724725 argHWTys <- mapM coreTypeToHWTypeM' argTys
725726
726727 (argExprs, concat -> argDecls) <- unzip <$>
727- mapM (\ (e,t) -> mkExpr False Concurrent (NetlistId dstId t) e)
728+ mapM (\ (e,t) -> mkExpr False declType (NetlistId dstId t) e)
728729 (zip args argTys)
729730
730731 -- Filter void arguments, but make sure to render their declarations:
@@ -735,7 +736,7 @@ mkFunApp dstId fun args tickDecls = do
735736 let compOutp = (\ (_,x,_) -> x) <$> listToMaybe co
736737 if length filteredTypeExprs == length compInps
737738 then do
738- (argExprs',argDecls') <- (second concat . unzip ) <$> mapM (toSimpleVar dstId) filteredTypeExprs
739+ (argExprs',argDecls') <- (second concat . unzip ) <$> mapM (toSimpleVar declType dstId) filteredTypeExprs
739740 let inpAssigns = zipWith (\ (i,t) e -> (Identifier i Nothing ,In ,t,e)) compInps argExprs'
740741 outpAssign = case compOutp of
741742 Nothing -> []
@@ -799,14 +800,16 @@ mkFunApp dstId fun args tickDecls = do
799800 "Maybe (Int -> Int)"
800801 |]
801802
802- toSimpleVar :: Identifier
803+ toSimpleVar :: DeclarationType
804+ -> Identifier
803805 -> (Expr ,Type )
804806 -> NetlistMonad (Expr ,[Declaration ])
805- toSimpleVar _ (e@ (Identifier _ Nothing ),_) = return (e,[] )
806- toSimpleVar dstId (e,ty) = do
807+ toSimpleVar _ _ (e@ (Identifier _ Nothing ),_) = return (e,[] )
808+ toSimpleVar declType dstId (e,ty) = do
807809 argNm <- Id. suffix dstId " fun_arg"
808810 hTy <- unsafeCoreTypeToHWTypeM' $ (curLoc) ty
809- argDecl <- mkInit Concurrent Cont argNm hTy e
811+ let assignTy = declTypeUsage declType
812+ argDecl <- mkInit declType assignTy argNm hTy e
810813 return (Identifier argNm Nothing , argDecl)
811814
812815-- | Generate an expression for a term occurring on the RHS of a let-binder
@@ -843,14 +846,14 @@ mkExpr bbEasD declType bndr app =
843846 | not (null tyArgs) -> invalid " Var-application with type arguments"
844847 | otherwise -> do
845848 argNm <- Id. suffix (netlistId1 id Id. unsafeFromCoreId bndr) " fun_arg"
846- decls <- mkFunApp argNm f tmArgs tickDecls
849+ decls <- mkFunApp declType argNm f tmArgs tickDecls
847850 if isVoid hwTyA then
848851 return (Noop , decls)
849852 else
850853 -- This net was already declared in the call to mkSelection.
851854 return ( Identifier argNm Nothing
852855 , NetDecl Nothing argNm hwTyA : decls)
853- Case scrut ty' [alt] -> mkProjection bbEasD bndr scrut ty' alt
856+ Case scrut ty' [alt] -> mkProjection declType bbEasD bndr scrut ty' alt
854857 Case scrut tyA (alt: alts) -> do
855858 argNm <- Id. suffix (netlistId1 id Id. unsafeFromCoreId bndr) " sel_arg"
856859 decls <- mkSelection declType (NetlistId argNm (netlistTypes1 bndr))
@@ -880,7 +883,8 @@ mkExpr bbEasD declType bndr app =
880883--
881884-- Works for both product types, as sum-of-product types.
882885mkProjection
883- :: Bool
886+ :: DeclarationType
887+ -> Bool
884888 -- ^ Projection must bind to a simple variable
885889 -> NetlistId
886890 -- ^ Name hint for the signal to which the projection is (potentially) assigned
@@ -891,8 +895,9 @@ mkProjection
891895 -> Alt
892896 -- ^ The field to be projected
893897 -> NetlistMonad (Expr , [Declaration ])
894- mkProjection mkDec bndr scrut altTy alt@ (pat,v) = do
898+ mkProjection declType mkDec bndr scrut altTy alt@ (pat,v) = do
895899 tcm <- Lens. view tcCache
900+ let assignTy = declTypeUsage declType
896901 let scrutTy = inferCoreTypeOf tcm scrut
897902 e = Case scrut scrutTy [alt]
898903 (_,sp) <- Lens. use curCompNm
@@ -909,7 +914,7 @@ mkProjection mkDec bndr scrut altTy alt@(pat,v) = do
909914 Id. next
910915 (\ b -> Id. suffix (Id. unsafeFromCoreId b) " projection" )
911916 bndr
912- (scrutExpr,newDecls) <- mkExpr False Concurrent (NetlistId scrutNm scrutTy) scrut
917+ (scrutExpr,newDecls) <- mkExpr False declType (NetlistId scrutNm scrutTy) scrut
913918 case scrutExpr of
914919 Identifier newId modM ->
915920 pure (Right (newId, modM, newDecls))
@@ -920,7 +925,7 @@ mkProjection mkDec bndr scrut altTy alt@(pat,v) = do
920925 -- TODO: seems useless?
921926 pure (Left newDecls)
922927 _ -> do
923- scrutDecl <- mkInit Concurrent Cont scrutNm sHwTy scrutExpr
928+ scrutDecl <- mkInit declType assignTy scrutNm sHwTy scrutExpr
924929 pure (Right (scrutNm, Nothing , newDecls ++ scrutDecl))
925930
926931 case scrutRendered of
@@ -957,7 +962,7 @@ mkProjection mkDec bndr scrut altTy alt@(pat,v) = do
957962 case bndr of
958963 NetlistId scrutNm _ | mkDec -> do
959964 scrutNm' <- Id. next scrutNm
960- scrutDecl <- mkInit Concurrent Cont scrutNm' vHwTy extractExpr
965+ scrutDecl <- mkInit declType assignTy scrutNm' vHwTy extractExpr
961966 return (Identifier scrutNm' Nothing , scrutDecl ++ decls)
962967 MultiId {} -> error " mkProjection: MultiId"
963968 _ -> return (extractExpr,decls)
@@ -985,7 +990,7 @@ mkDcApplication declType [dstHType] bndr dc args = do
985990 let dcNm = nameOcc (dcName dc)
986991 tcm <- Lens. view tcCache
987992 let argTys = map (inferCoreTypeOf tcm) args
988- argNm <- netlistId1 return (\ b -> Id. suffix (Id. unsafeFromCoreId b) " _dc_arg " ) bndr
993+ argNm <- netlistId1 return (\ b -> Id. suffix (Id. unsafeFromCoreId b) " dc_arg " ) bndr
989994 argHWTys <- mapM coreTypeToHWTypeM' argTys
990995
991996 (argExprs, concat -> argDecls) <- unzip <$>
0 commit comments