@@ -85,7 +85,7 @@ genNetlist
8585 -- ^ Custom bit representations for certain types
8686 -> BindingMap
8787 -- ^ Global binders
88- -> [( Id , Maybe TopEntity , Maybe Id ) ]
88+ -> [TopEntityT ]
8989 -- ^ All the TopEntities
9090 -> CompiledPrimMap
9191 -- ^ Primitive definitions
@@ -114,17 +114,15 @@ genNetlist
114114 -- ^ Name of the @topEntity@
115115 -> IO ([([Bool ],SrcSpan ,HashMap Identifier Word ,Component )],HashMap Identifier Word )
116116genNetlist isTb opts reprs globals tops primMap tcm typeTrans iw mkId extId ite be seen env prefixM topEntity = do
117- (_,s) <- runNetlistMonad isTb opts reprs globals (mkTopEntityMap tops)
117+ (_,s) <- runNetlistMonad isTb opts reprs globals topEntityMap
118118 primMap tcm typeTrans iw mkId extId ite be seen env prefixM $
119119 genComponent topEntity
120120 return ( eltsVarEnv $ _components s
121121 , _seenComps s
122122 )
123123 where
124- mkTopEntityMap
125- :: [(Id ,Maybe TopEntity ,Maybe Id )]
126- -> VarEnv (Type ,Maybe TopEntity )
127- mkTopEntityMap = mkVarEnv . map (\ (a,b,_) -> (a,(varType a,b)))
124+ topEntityMap :: VarEnv TopEntityT
125+ topEntityMap = mkVarEnv (zip (map topId tops) tops)
128126
129127-- | Run a NetlistMonad action in a given environment
130128runNetlistMonad
@@ -136,7 +134,7 @@ runNetlistMonad
136134 -- ^ Custom bit representations for certain types
137135 -> BindingMap
138136 -- ^ Global binders
139- -> VarEnv ( Type , Maybe TopEntity )
137+ -> VarEnv TopEntityT
140138 -- ^ TopEntity annotations
141139 -> CompiledPrimMap
142140 -- ^ Primitive Definitions
@@ -219,7 +217,7 @@ genComponentT
219217genComponentT compName componentExpr = do
220218 varCount .= 0
221219 componentName1 <- (`lookupVarEnv'` compName) <$> Lens. use componentNames
222- topEntMM <- fmap snd . lookupVarEnv compName <$> Lens. use topEntityAnns
220+ topEntMM <- fmap topAnnotation . lookupVarEnv compName <$> Lens. use topEntityAnns
223221 prefixM <- Lens. use componentPrefix
224222 let componentName2 = case (prefixM,join topEntMM) of
225223 ((Just p,_),Just ann) -> p `StrictText.append` StrictText. pack (' _' : t_name ann)
@@ -233,8 +231,8 @@ genComponentT compName componentExpr = do
233231 -- HACK: Determine resulttype of this function by looking at its definition
234232 -- in topEntityAnns, instead of looking at its last binder (which obscure
235233 -- any attributes [see: Clash.Annotations.SynthesisAttributes]).
236- topEntityTypeM <- lookupVarEnv compName <$> Lens. use topEntityAnns
237- let topEntityTypeM' = snd . splitCoreFunForallTy tcm . fst <$> topEntityTypeM
234+ topEntityTypeM <- lookupVarEnv compName <$> Lens. use topEntityAnns
235+ let topEntityTypeM' = snd . splitCoreFunForallTy tcm . varType . topId <$> topEntityTypeM
238236
239237 seenIds .= HashMapS. empty
240238 (wereVoids,compInps,argWrappers,compOutps,resUnwrappers,binders,resultM) <-
@@ -564,13 +562,15 @@ mkFunApp dstId fun args tickDecls = do
564562 topAnns <- Lens. use topEntityAnns
565563 tcm <- Lens. use tcCache
566564 case lookupVarEnv fun topAnns of
567- Just (ty,annM)
568- | let (fArgTys0,fResTy) = splitFunTys tcm ty
565+ Just topEntity
566+ | let ty = varType (topId topEntity)
567+ , let (fArgTys0,fResTy) = splitFunTys tcm ty
569568 -- Take into account that clocks and stuff are split off from any product
570569 -- types containing them
571570 , let fArgTys1 = splitShouldSplit tcm fArgTys0
572571 , length fArgTys1 == length args
573572 -> do
573+ let annM = topAnnotation topEntity
574574 argHWTys <- mapM (unsafeCoreTypeToHWTypeM' $ (curLoc)) fArgTys1
575575 (argExprs, concat -> argDecls) <- unzip <$>
576576 mapM (\ (e,t) -> mkExpr False Concurrent (NetlistId dstId t) e)
0 commit comments