--- | List version of genExprFCall1
-genExprFCall1L :: AST.VHDLId -> [AST.Expr] -> AST.Expr
-genExprFCall1L fName [arg] = genExprFCall fName [arg]
-genExprFCall1L _ _ = error "Generate.genExprFCall1L incorrect length"
-
--- | List version of genExprFCall2
-genExprFCall2L :: AST.VHDLId -> [AST.Expr] -> AST.Expr
-genExprFCall2L fName [arg1, arg2] = genExprFCall fName [arg1,arg2]
-genExprFCall2L _ _ = error "Generate.genExprFCall2L incorrect length"
+-- | Generate a generate statement for the builtin function "map"
+genMapCall ::
+ Int -- | The length of the vector
+ -> Entity -- | The entity to map
+ -> AST.VHDLId -- | The input vector
+ -> AST.VHDLId -- | The output vector
+ -> AST.GenerateSm -- | The resulting generate statement
+genMapCall len entity arg res = genSm
+ where
+ label = AST.unsafeVHDLBasicId "mapVector"
+ nPar = AST.unsafeVHDLBasicId "n"
+ range = AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (len-1))
+ genScheme = AST.ForGn nPar range
+ entity_id = ent_id entity
+ argport = map (Monad.liftM fst) (ent_args entity)
+ resport = (Monad.liftM fst) (ent_res entity)
+ inport = mkAssocElem (head argport) arg
+ outport = mkAssocElem resport res
+ portmaps = Maybe.catMaybes [inport,outport]
+ portmap = AST.CSISm $ AST.CompInsSm (AST.unsafeVHDLBasicId "map12") (AST.IUEntity (AST.NSimple entity_id)) (AST.PMapAspect portmaps)
+ genSm = AST.GenerateSm label genScheme [] [portmap]
+ -- | Create an VHDL port -> signal association
+ mkAssocElem :: Maybe AST.VHDLId -> AST.VHDLId -> Maybe AST.AssocElem
+ mkAssocElem (Just port) signal = Just $ Just port AST.:=>: (AST.ADName (AST.NIndexed (AST.IndexedName
+ (AST.NSimple signal) [AST.PrimName $ AST.NSimple nPar])))
+ mkAssocElem Nothing _ = Nothing