-- constructor from the AST.Expr type, e.g. AST.And.
genExprOp2 :: (AST.Expr -> AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr
genExprOp2 op [arg1, arg2] = op arg1 arg2
-genExprOp2 _ _ = error "Generate.genExprOp2 wrong number of argumetns"
-- | Generate a unary operator application
genExprOp1 :: (AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr
genExprOp1 op [arg] = op arg
-genExprOp1 _ _ = error "Generate.genExprOp1 wrong number of argumetns"
-- | Generate a function call from the Function Name and a list of expressions
-- (its arguments)
AST.PrimFCall $ AST.FCall (AST.NSimple fName) $
map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args
--- | 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"
-
genUnconsVectorFuns :: AST.TypeMark -- ^ type of the vector elements
-> AST.TypeMark -- ^ type of the vector
-> [AST.SubProgBody]
globalNameTable :: NameTable
globalNameTable = mkGlobalNameTable
- [ ("!" , (2, genExprFCall2L exId ) )
- , ("head" , (1, genExprFCall1L headId ) )
+ [ ("!" , (2, genExprFCall exId ) )
+ , ("head" , (1, genExprFCall headId ) )
, ("hwxor" , (2, genExprOp2 AST.Xor ) )
, ("hwand" , (2, genExprOp2 AST.And ) )
, ("hwor" , (2, genExprOp2 AST.And ) )
-- functions.
funSignatures <- getA vsNameTable
case (Map.lookup (bndrToString f) funSignatures) of
- Just funSignature ->
- let
- sigs = map (bndrToString.varBndr) args
- sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs
- func = (snd funSignature) sigsNames
- src_wform = AST.Wform [AST.WformElem func Nothing]
- dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr))
- assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing)
- in
- return $ AST.CSSASm assign
+ Just (arg_count, builder) ->
+ if length args == arg_count then
+ let
+ sigs = map (bndrToString.varBndr) args
+ sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs
+ func = builder sigsNames
+ src_wform = AST.Wform [AST.WformElem func Nothing]
+ dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr))
+ assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing)
+ in
+ return $ AST.CSSASm assign
+ else
+ error $ "VHDL.mkConcSm Incorrect number of arguments to builtin function: " ++ pprString f ++ " Args: " ++ pprString args
Nothing -> error $ "Using function from another module that is not a known builtin: " ++ pprString f
IdInfo.NotGlobalId -> do
signatures <- getA vsSignatures