4 import qualified Control.Monad as Monad
5 import qualified Data.Map as Map
11 import qualified ForSyDe.Backend.VHDL.AST as AST
25 -- | A function to wrap a builder-like function that expects its arguments to
28 (dst -> func -> [AST.Expr] -> res)
29 -> (dst -> func -> [CoreSyn.CoreExpr] -> res)
30 genExprArgs wrap dst func args = wrap dst func args'
31 where args' = map (varToVHDLExpr.exprToVar) args
33 -- | A function to wrap a builder-like function that expects its arguments to
36 (dst -> func -> [Var.Var] -> res)
37 -> (dst -> func -> [CoreSyn.CoreExpr] -> res)
38 genVarArgs wrap dst func args = wrap dst func args'
39 where args' = map exprToVar args
41 -- | A function to wrap a builder-like function that produces an expression
42 -- and expects it to be assigned to the destination.
44 (CoreSyn.CoreBndr -> func -> [arg] -> VHDLSession AST.Expr)
45 -> (CoreSyn.CoreBndr -> func -> [arg] -> VHDLSession [AST.ConcSm])
46 genExprRes wrap dst func args = do
47 expr <- wrap dst func args
48 return $ [mkUncondAssign (Left dst) expr]
50 -- | Generate a binary operator application. The first argument should be a
51 -- constructor from the AST.Expr type, e.g. AST.And.
52 genOperator2 :: (AST.Expr -> AST.Expr -> AST.Expr) -> BuiltinBuilder
53 genOperator2 op = genExprArgs $ genExprRes (genOperator2' op)
54 genOperator2' :: (AST.Expr -> AST.Expr -> AST.Expr) -> CoreSyn.CoreBndr -> CoreSyn.CoreBndr -> [AST.Expr] -> VHDLSession AST.Expr
55 genOperator2' op res f [arg1, arg2] = return $ op arg1 arg2
57 -- | Generate a unary operator application
58 genOperator1 :: (AST.Expr -> AST.Expr) -> BuiltinBuilder
59 genOperator1 op = genExprArgs $ genExprRes (genOperator1' op)
60 genOperator1' :: (AST.Expr -> AST.Expr) -> CoreSyn.CoreBndr -> CoreSyn.CoreBndr -> [AST.Expr] -> VHDLSession AST.Expr
61 genOperator1' op res f [arg] = return $ op arg
63 -- | Generate a function call from the destination binder, function name and a
64 -- list of expressions (its arguments)
65 genFCall :: BuiltinBuilder
66 genFCall = genExprArgs $ genExprRes genFCall'
67 genFCall' :: CoreSyn.CoreBndr -> CoreSyn.CoreBndr -> [AST.Expr] -> VHDLSession AST.Expr
68 genFCall' res f args = do
69 let fname = varToString f
70 let el_ty = (tfvec_elem . Var.varType) res
71 id <- vectorFunId el_ty fname
72 return $ AST.PrimFCall $ AST.FCall (AST.NSimple id) $
73 map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args
75 -- | Generate a generate statement for the builtin function "map"
76 genMap :: BuiltinBuilder
77 genMap = genVarArgs genMap'
78 genMap' res f [mapped_f, arg] = do
79 signatures <- getA vsSignatures
80 let entity = Maybe.fromMaybe
81 (error $ "Using function '" ++ (varToString mapped_f) ++ "' without signature? This should not happen!")
82 (Map.lookup mapped_f signatures)
84 -- Setup the generate scheme
85 len = (tfvec_len . Var.varType) res
86 label = mkVHDLExtId ("mapVector" ++ (varToString res))
87 nPar = AST.unsafeVHDLBasicId "n"
88 range = AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (len-1))
89 genScheme = AST.ForGn nPar range
90 -- Get the entity name and port names
91 entity_id = ent_id entity
92 argports = map (Monad.liftM fst) (ent_args entity)
93 resport = (Monad.liftM fst) (ent_res entity)
95 inport = mkAssocElemIndexed (argports!!0) (varToVHDLId arg) nPar
96 outport = mkAssocElemIndexed resport (varToVHDLId res) nPar
97 portassigns = Maybe.catMaybes [inport,outport]
98 -- Generate the portmap
99 mapLabel = "map" ++ (AST.fromVHDLId entity_id)
100 compins = mkComponentInst mapLabel entity_id portassigns
101 -- Return the generate functions
102 genSm = AST.CSGSm $ AST.GenerateSm label genScheme [] [compins]
106 genZipWith :: BuiltinBuilder
107 genZipWith = genVarArgs genZipWith'
108 genZipWith' res f args@[zipped_f, arg1, arg2] = do
109 signatures <- getA vsSignatures
110 let entity = Maybe.fromMaybe
111 (error $ "Using function '" ++ (varToString zipped_f) ++ "' without signature? This should not happen!")
112 (Map.lookup zipped_f signatures)
114 -- Setup the generate scheme
115 len = (tfvec_len . Var.varType) res
116 label = mkVHDLExtId ("zipWithVector" ++ (varToString res))
117 nPar = AST.unsafeVHDLBasicId "n"
118 range = AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (len-1))
119 genScheme = AST.ForGn nPar range
120 -- Get the entity name and port names
121 entity_id = ent_id entity
122 argports = map (Monad.liftM fst) (ent_args entity)
123 resport = (Monad.liftM fst) (ent_res entity)
125 inport1 = mkAssocElemIndexed (argports!!0) (varToVHDLId arg1) nPar
126 inport2 = mkAssocElemIndexed (argports!!1) (varToVHDLId arg2) nPar
127 outport = mkAssocElemIndexed resport (varToVHDLId res) nPar
128 portassigns = Maybe.catMaybes [inport1,inport2,outport]
129 -- Generate the portmap
130 mapLabel = "zipWith" ++ (AST.fromVHDLId entity_id)
131 compins = mkComponentInst mapLabel entity_id portassigns
132 -- Return the generate functions
133 genSm = AST.CSGSm $ AST.GenerateSm label genScheme [] [compins]
137 genFoldl :: BuiltinBuilder
138 genFoldl = genVarArgs genFoldl'
139 genFoldl' resVal f [folded_f, startVal, inVec] = do
140 signatures <- getA vsSignatures
141 let entity = Maybe.fromMaybe
142 (error $ "Using function '" ++ (varToString folded_f) ++ "' without signature? This should not happen!")
143 (Map.lookup folded_f signatures)
144 let (vec, _) = splitAppTy (Var.varType inVec)
145 let vecty = Type.mkAppTy vec (Var.varType startVal)
146 vecType <- vhdl_ty vecty
147 -- Setup the generate scheme
148 let len = (tfvec_len . Var.varType) inVec
149 let genlabel = mkVHDLExtId ("foldlVector" ++ (varToString inVec))
150 let blockLabel = mkVHDLExtId ("foldlVector" ++ (varToString startVal))
151 let range = AST.ToRange (AST.PrimLit "0") (AST.PrimLit $ show (len-1))
152 let genScheme = AST.ForGn (AST.unsafeVHDLBasicId "n") range
153 -- Make the intermediate vector
154 let tmpId = mkVHDLExtId "tmp"
155 let tmpVec = AST.BDISD $ AST.SigDec tmpId vecType Nothing
156 -- Get the entity name and port names
157 let entity_id = ent_id entity
158 let argports = map (Monad.liftM fst) (ent_args entity)
159 let resport = (Monad.liftM fst) (ent_res entity)
160 -- Generate the output assignment
161 let assign = [mkUncondAssign (Left resVal) (AST.PrimName (AST.NIndexed (AST.IndexedName
162 (AST.NSimple tmpId) [AST.PrimLit $ show (len-1)])))]
163 -- Return the generate functions
164 let genSm = AST.CSGSm $ AST.GenerateSm genlabel genScheme []
165 [ AST.CSGSm (genFirstCell (entity_id, argports, resport)
166 [startVal, inVec, resVal])
167 , AST.CSGSm (genOtherCell (entity_id, argports, resport)
168 [startVal, inVec, resVal])
170 return $ if len > 0 then
171 [AST.CSBSm $ AST.BlockSm blockLabel [] (AST.PMapAspect []) [tmpVec] (genSm : assign)]
173 [mkUncondAssign (Left resVal) (AST.PrimName $ AST.NSimple (varToVHDLId startVal))]
175 genFirstCell (entity_id, argports, resport) [startVal, inVec, resVal] = cellGn
177 cellLabel = mkVHDLExtId "firstcell"
178 cellGenScheme = AST.IfGn ((AST.PrimName $ AST.NSimple nPar) AST.:=: (AST.PrimLit "0"))
179 tmpId = mkVHDLExtId "tmp"
180 nPar = AST.unsafeVHDLBasicId "n"
182 inport1 = mkAssocElem (argports!!0) (varToString startVal)
183 inport2 = mkAssocElemIndexed (argports!!1) (varToVHDLId inVec) nPar
184 outport = mkAssocElemIndexed resport tmpId nPar
185 portassigns = Maybe.catMaybes [inport1,inport2,outport]
186 -- Generate the portmap
187 mapLabel = "cell" ++ (AST.fromVHDLId entity_id)
188 compins = mkComponentInst mapLabel entity_id portassigns
189 -- Return the generate functions
190 cellGn = AST.GenerateSm cellLabel cellGenScheme [] [compins]
191 genOtherCell (entity_id, argports, resport) [startVal, inVec, resVal] = cellGn
193 len = (tfvec_len . Var.varType) inVec
194 cellLabel = mkVHDLExtId "othercell"
195 cellGenScheme = AST.IfGn ((AST.PrimName $ AST.NSimple nPar) AST.:/=: (AST.PrimLit "0"))
196 -- ((AST.PrimName $ AST.NSimple nPar) AST.:<: (AST.PrimLit $ show (len-1)))
197 tmpId = mkVHDLExtId "tmp"
198 nPar = AST.unsafeVHDLBasicId "n"
200 inport1 = mkAssocElemIndexed (argports!!0) tmpId (AST.unsafeVHDLBasicId "n-1")
201 inport2 = mkAssocElemIndexed (argports!!1) (varToVHDLId inVec) nPar
202 outport = mkAssocElemIndexed resport tmpId nPar
203 portassigns = Maybe.catMaybes [inport1,inport2,outport]
204 -- Generate the portmap
205 mapLabel = "cell" ++ (AST.fromVHDLId entity_id)
206 compins = mkComponentInst mapLabel entity_id portassigns
207 -- Return the generate functions
208 cellGn = AST.GenerateSm cellLabel cellGenScheme [] [compins]
210 genFoldr :: BuiltinBuilder
211 genFoldr = genVarArgs genFoldr'
212 genFoldr' resVal f [folded_f, startVal, inVec] = do
213 signatures <- getA vsSignatures
214 let entity = Maybe.fromMaybe
215 (error $ "Using function '" ++ (varToString folded_f) ++ "' without signature? This should not happen!")
216 (Map.lookup folded_f signatures)
217 let (vec, _) = splitAppTy (Var.varType inVec)
218 let vecty = Type.mkAppTy vec (Var.varType startVal)
219 vecType <- vhdl_ty vecty
220 -- Setup the generate scheme
221 let len = (tfvec_len . Var.varType) inVec
222 let genlabel = mkVHDLExtId ("foldrVector" ++ (varToString inVec))
223 let blockLabel = mkVHDLExtId ("foldrVector" ++ (varToString startVal))
224 let range = AST.DownRange (AST.PrimLit $ show (len-1)) (AST.PrimLit "0")
225 let genScheme = AST.ForGn (AST.unsafeVHDLBasicId "n") range
226 -- Make the intermediate vector
227 let tmpId = mkVHDLExtId "tmp"
228 let tmpVec = AST.BDISD $ AST.SigDec tmpId vecType Nothing
229 -- Get the entity name and port names
230 let entity_id = ent_id entity
231 let argports = map (Monad.liftM fst) (ent_args entity)
232 let resport = (Monad.liftM fst) (ent_res entity)
233 -- Generate the output assignment
234 let assign = [mkUncondAssign (Left resVal) (AST.PrimName (AST.NIndexed (AST.IndexedName
235 (AST.NSimple tmpId) [AST.PrimLit "0"])))]
236 -- Return the generate functions
237 let genSm = AST.CSGSm $ AST.GenerateSm genlabel genScheme []
238 [ AST.CSGSm (genFirstCell len (entity_id, argports, resport)
239 [startVal, inVec, resVal])
240 , AST.CSGSm (genOtherCell len (entity_id, argports, resport)
241 [startVal, inVec, resVal])
243 return $ if len > 0 then
244 [AST.CSBSm $ AST.BlockSm blockLabel [] (AST.PMapAspect []) [tmpVec] (genSm : assign)]
246 [mkUncondAssign (Left resVal) (AST.PrimName $ AST.NSimple (varToVHDLId startVal))]
248 genFirstCell len (entity_id, argports, resport) [startVal, inVec, resVal] = cellGn
250 cellLabel = mkVHDLExtId "firstcell"
251 cellGenScheme = AST.IfGn ((AST.PrimName $ AST.NSimple nPar) AST.:=: (AST.PrimLit $ show (len-1)))
252 tmpId = mkVHDLExtId "tmp"
253 nPar = AST.unsafeVHDLBasicId "n"
255 inport1 = mkAssocElem (argports!!0) (varToString startVal)
256 inport2 = mkAssocElemIndexed (argports!!1) (varToVHDLId inVec) nPar
257 outport = mkAssocElemIndexed resport tmpId nPar
258 portassigns = Maybe.catMaybes [inport1,inport2,outport]
259 -- Generate the portmap
260 mapLabel = "cell" ++ (AST.fromVHDLId entity_id)
261 compins = mkComponentInst mapLabel entity_id portassigns
262 -- Return the generate functions
263 cellGn = AST.GenerateSm cellLabel cellGenScheme [] [compins]
264 genOtherCell len (entity_id, argports, resport) [startVal, inVec, resVal] = cellGn
266 len = (tfvec_len . Var.varType) inVec
267 cellLabel = mkVHDLExtId "othercell"
268 cellGenScheme = AST.IfGn ((AST.PrimName $ AST.NSimple nPar) AST.:/=: (AST.PrimLit $ show (len-1)))
269 -- ((AST.PrimName $ AST.NSimple nPar) AST.:<: (AST.PrimLit $ show (len-1)))
270 tmpId = mkVHDLExtId "tmp"
271 nPar = AST.unsafeVHDLBasicId "n"
273 inport1 = mkAssocElemIndexed (argports!!0) tmpId (AST.unsafeVHDLBasicId "n+1")
274 inport2 = mkAssocElemIndexed (argports!!1) (varToVHDLId inVec) nPar
275 outport = mkAssocElemIndexed resport tmpId nPar
276 portassigns = Maybe.catMaybes [inport1,inport2,outport]
277 -- Generate the portmap
278 mapLabel = "cell" ++ (AST.fromVHDLId entity_id)
279 compins = mkComponentInst mapLabel entity_id portassigns
280 -- Return the generate functions
281 cellGn = AST.GenerateSm cellLabel cellGenScheme [] [compins]
283 -- Returns the VHDLId of the vector function with the given name for the given
284 -- element type. Generates -- this function if needed.
285 vectorFunId :: Type.Type -> String -> VHDLSession AST.VHDLId
286 vectorFunId el_ty fname = do
287 elemTM <- vhdl_ty el_ty
288 -- TODO: This should not be duplicated from mk_vector_ty. Probably but it in
289 -- the VHDLState or something.
290 let vectorTM = mkVHDLExtId $ "vector_" ++ (AST.fromVHDLId elemTM)
291 typefuns <- getA vsTypeFuns
292 case Map.lookup (OrdType el_ty, fname) typefuns of
293 -- Function already generated, just return it
294 Just (id, _) -> return id
295 -- Function not generated yet, generate it
297 let functions = genUnconsVectorFuns elemTM vectorTM
298 case lookup fname functions of
300 modA vsTypeFuns $ Map.insert (OrdType el_ty, fname) (function_id, body)
302 Nothing -> error $ "I don't know how to generate vector function " ++ fname
304 function_id = mkVHDLExtId fname
306 genUnconsVectorFuns :: AST.TypeMark -- ^ type of the vector elements
307 -> AST.TypeMark -- ^ type of the vector
308 -> [(String, AST.SubProgBody)]
309 genUnconsVectorFuns elemTM vectorTM =
310 [ (exId, AST.SubProgBody exSpec [] [exExpr])
311 , (replaceId, AST.SubProgBody replaceSpec [AST.SPVD replaceVar] [replaceExpr,replaceRet])
312 , (headId, AST.SubProgBody headSpec [] [headExpr])
313 , (lastId, AST.SubProgBody lastSpec [] [lastExpr])
314 , (initId, AST.SubProgBody initSpec [AST.SPVD initVar] [initExpr, initRet])
315 , (tailId, AST.SubProgBody tailSpec [AST.SPVD tailVar] [tailExpr, tailRet])
316 , (takeId, AST.SubProgBody takeSpec [AST.SPVD takeVar] [takeExpr, takeRet])
317 , (dropId, AST.SubProgBody dropSpec [AST.SPVD dropVar] [dropExpr, dropRet])
318 , (plusgtId, AST.SubProgBody plusgtSpec [AST.SPVD plusgtVar] [plusgtExpr, plusgtRet])
319 , (emptyId, AST.SubProgBody emptySpec [AST.SPCD emptyVar] [emptyExpr])
320 , (singletonId, AST.SubProgBody singletonSpec [AST.SPVD singletonVar] [singletonRet])
321 , (copyId, AST.SubProgBody copySpec [AST.SPVD copyVar] [copyExpr])
324 ixPar = AST.unsafeVHDLBasicId "ix"
325 vecPar = AST.unsafeVHDLBasicId "vec"
326 nPar = AST.unsafeVHDLBasicId "n"
327 iId = AST.unsafeVHDLBasicId "i"
329 aPar = AST.unsafeVHDLBasicId "a"
330 resId = AST.unsafeVHDLBasicId "res"
331 exSpec = AST.Function (mkVHDLExtId exId) [AST.IfaceVarDec vecPar vectorTM,
332 AST.IfaceVarDec ixPar naturalTM] elemTM
333 exExpr = AST.ReturnSm (Just $ AST.PrimName $ AST.NIndexed
334 (AST.IndexedName (AST.NSimple vecPar) [AST.PrimName $
336 replaceSpec = AST.Function (mkVHDLExtId replaceId) [ AST.IfaceVarDec vecPar vectorTM
337 , AST.IfaceVarDec iPar naturalTM
338 , AST.IfaceVarDec aPar elemTM
340 -- variable res : fsvec_x (0 to vec'length-1);
343 (AST.SubtypeIn vectorTM
344 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
345 [AST.ToRange (AST.PrimLit "0")
346 (AST.PrimName (AST.NAttribute $
347 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing) AST.:-:
348 (AST.PrimLit "1")) ]))
350 -- res AST.:= vec(0 to i-1) & a & vec(i+1 to length'vec-1)
351 replaceExpr = AST.NSimple resId AST.:=
352 (vecSlice (AST.PrimLit "0") (AST.PrimName (AST.NSimple iPar) AST.:-: AST.PrimLit "1") AST.:&:
353 AST.PrimName (AST.NSimple aPar) AST.:&:
354 vecSlice (AST.PrimName (AST.NSimple iPar) AST.:+: AST.PrimLit "1")
355 ((AST.PrimName (AST.NAttribute $
356 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing))
357 AST.:-: AST.PrimLit "1"))
358 replaceRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
359 vecSlice init last = AST.PrimName (AST.NSlice
362 (AST.ToRange init last)))
363 headSpec = AST.Function (mkVHDLExtId headId) [AST.IfaceVarDec vecPar vectorTM] elemTM
365 headExpr = AST.ReturnSm (Just $ (AST.PrimName $ AST.NIndexed (AST.IndexedName
366 (AST.NSimple vecPar) [AST.PrimLit "0"])))
367 lastSpec = AST.Function (mkVHDLExtId lastId) [AST.IfaceVarDec vecPar vectorTM] elemTM
368 -- return vec(vec'length-1);
369 lastExpr = AST.ReturnSm (Just $ (AST.PrimName $ AST.NIndexed (AST.IndexedName
371 [AST.PrimName (AST.NAttribute $
372 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing)
373 AST.:-: AST.PrimLit "1"])))
374 initSpec = AST.Function (mkVHDLExtId initId) [AST.IfaceVarDec vecPar vectorTM] vectorTM
375 -- variable res : fsvec_x (0 to vec'length-2);
378 (AST.SubtypeIn vectorTM
379 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
380 [AST.ToRange (AST.PrimLit "0")
381 (AST.PrimName (AST.NAttribute $
382 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing) AST.:-:
383 (AST.PrimLit "2")) ]))
385 -- resAST.:= vec(0 to vec'length-2)
386 initExpr = AST.NSimple resId AST.:= (vecSlice
388 (AST.PrimName (AST.NAttribute $
389 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing)
390 AST.:-: AST.PrimLit "2"))
391 initRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
392 tailSpec = AST.Function (mkVHDLExtId tailId) [AST.IfaceVarDec vecPar vectorTM] vectorTM
393 -- variable res : fsvec_x (0 to vec'length-2);
396 (AST.SubtypeIn vectorTM
397 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
398 [AST.ToRange (AST.PrimLit "0")
399 (AST.PrimName (AST.NAttribute $
400 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing) AST.:-:
401 (AST.PrimLit "2")) ]))
403 -- res AST.:= vec(1 to vec'length-1)
404 tailExpr = AST.NSimple resId AST.:= (vecSlice
406 (AST.PrimName (AST.NAttribute $
407 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing)
408 AST.:-: AST.PrimLit "1"))
409 tailRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
410 takeSpec = AST.Function (mkVHDLExtId takeId) [AST.IfaceVarDec nPar naturalTM,
411 AST.IfaceVarDec vecPar vectorTM ] vectorTM
412 -- variable res : fsvec_x (0 to n-1);
415 (AST.SubtypeIn vectorTM
416 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
417 [AST.ToRange (AST.PrimLit "0")
418 ((AST.PrimName (AST.NSimple nPar)) AST.:-:
419 (AST.PrimLit "1")) ]))
421 -- res AST.:= vec(0 to n-1)
422 takeExpr = AST.NSimple resId AST.:=
423 (vecSlice (AST.PrimLit "1")
424 (AST.PrimName (AST.NSimple $ nPar) AST.:-: AST.PrimLit "1"))
425 takeRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
426 dropSpec = AST.Function (mkVHDLExtId dropId) [AST.IfaceVarDec nPar naturalTM,
427 AST.IfaceVarDec vecPar vectorTM ] vectorTM
428 -- variable res : fsvec_x (0 to vec'length-n-1);
431 (AST.SubtypeIn vectorTM
432 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
433 [AST.ToRange (AST.PrimLit "0")
434 (AST.PrimName (AST.NAttribute $
435 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing) AST.:-:
436 (AST.PrimName $ AST.NSimple nPar)AST.:-: (AST.PrimLit "1")) ]))
438 -- res AST.:= vec(n to vec'length-1)
439 dropExpr = AST.NSimple resId AST.:= (vecSlice
440 (AST.PrimName $ AST.NSimple nPar)
441 (AST.PrimName (AST.NAttribute $
442 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing)
443 AST.:-: AST.PrimLit "1"))
444 dropRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
445 plusgtSpec = AST.Function (mkVHDLExtId plusgtId) [AST.IfaceVarDec aPar elemTM,
446 AST.IfaceVarDec vecPar vectorTM] vectorTM
447 -- variable res : fsvec_x (0 to vec'length);
450 (AST.SubtypeIn vectorTM
451 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
452 [AST.ToRange (AST.PrimLit "0")
453 (AST.PrimName (AST.NAttribute $
454 AST.AttribName (AST.NSimple vecPar) (mkVHDLBasicId lengthId) Nothing))]))
456 plusgtExpr = AST.NSimple resId AST.:=
457 ((AST.PrimName $ AST.NSimple aPar) AST.:&:
458 (AST.PrimName $ AST.NSimple vecPar))
459 plusgtRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
460 emptySpec = AST.Function (mkVHDLExtId emptyId) [] vectorTM
463 (AST.SubtypeIn vectorTM Nothing)
464 (Just $ AST.PrimLit "\"\"")
465 emptyExpr = AST.ReturnSm (Just $ AST.PrimName (AST.NSimple resId))
466 singletonSpec = AST.Function (mkVHDLExtId singletonId) [AST.IfaceVarDec aPar elemTM ]
468 -- variable res : fsvec_x (0 to 0) := (others => a);
471 (AST.SubtypeIn vectorTM
472 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
473 [AST.ToRange (AST.PrimLit "0") (AST.PrimLit "0")]))
474 (Just $ AST.Aggregate [AST.ElemAssoc (Just AST.Others)
475 (AST.PrimName $ AST.NSimple aPar)])
476 singletonRet = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)
477 copySpec = AST.Function (mkVHDLExtId copyId) [AST.IfaceVarDec nPar naturalTM,
478 AST.IfaceVarDec aPar elemTM ] vectorTM
479 -- variable res : fsvec_x (0 to n-1) := (others => a);
482 (AST.SubtypeIn vectorTM
483 (Just $ AST.ConstraintIndex $ AST.IndexConstraint
484 [AST.ToRange (AST.PrimLit "0")
485 ((AST.PrimName (AST.NSimple nPar)) AST.:-:
486 (AST.PrimLit "1")) ]))
487 (Just $ AST.Aggregate [AST.ElemAssoc (Just AST.Others)
488 (AST.PrimName $ AST.NSimple aPar)])
490 copyExpr = AST.ReturnSm (Just $ AST.PrimName $ AST.NSimple resId)