import Constants
import Generate
-mkGlobalNameTable :: [(String, (Int, [AST.Expr] -> AST.Expr ) )] -> NameTable
+mkGlobalNameTable :: [(String, (Int, Builder) )] -> NameTable
mkGlobalNameTable = Map.fromList
globalNameTable :: NameTable
globalNameTable = mkGlobalNameTable
- [ ("!" , (2, genExprFCall exId ) )
- , ("replace" , (3, genExprFCall replaceId ) )
- , ("head" , (1, genExprFCall headId ) )
- , ("last" , (1, genExprFCall lastId ) )
- , ("tail" , (1, genExprFCall tailId ) )
- , ("init" , (1, genExprFCall initId ) )
- , ("take" , (2, genExprFCall takeId ) )
- , ("drop" , (2, genExprFCall dropId ) )
- , ("+>" , (2, genExprFCall plusgtId ) )
- , ("empty" , (0, genExprFCall emptyId ) )
- , ("hwxor" , (2, genExprOp2 AST.Xor ) )
- , ("hwand" , (2, genExprOp2 AST.And ) )
- , ("hwor" , (2, genExprOp2 AST.Or ) )
- , ("hwnot" , (1, genExprOp1 AST.Not ) )
+ [ ("!" , (2, Left $ genExprFCall exId ) )
+ , ("replace" , (3, Left $ genExprFCall replaceId ) )
+ , ("head" , (1, Left $ genExprFCall headId ) )
+ , ("last" , (1, Left $ genExprFCall lastId ) )
+ , ("tail" , (1, Left $ genExprFCall tailId ) )
+ , ("init" , (1, Left $ genExprFCall initId ) )
+ , ("take" , (2, Left $ genExprFCall takeId ) )
+ , ("drop" , (2, Left $ genExprFCall dropId ) )
+ , ("+>" , (2, Left $ genExprFCall plusgtId ) )
+ , ("map" , (2, Right $ genMapCall ) )
+ , ("empty" , (0, Left $ genExprFCall emptyId ) )
+ , ("hwxor" , (2, Left $ genExprOp2 AST.Xor ) )
+ , ("hwand" , (2, Left $ genExprOp2 AST.And ) )
+ , ("hwor" , (2, Left $ genExprOp2 AST.Or ) )
+ , ("hwnot" , (1, Left $ genExprOp1 AST.Not ) )
]
-- It's a global value imported from elsewhere. These can be builtin
-- functions.
funSignatures <- getA vsNameTable
+ entSignatures <- getA vsSignatures
case (Map.lookup (bndrToString f) funSignatures) of
Just (arg_count, builder) ->
if length valargs == arg_count then
- let
- sigs = map (bndrToString.varBndr) valargs
- 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]
+ case builder of
+ Left funBuilder ->
+ let
+ sigs = map (bndrToString.varBndr) valargs
+ sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs
+ func = funBuilder 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]
+ Right genBuilder ->
+ let
+ sigs = map (varBndr) valargs
+ signature = Maybe.fromMaybe
+ (error $ "Using function '" ++ (bndrToString (head sigs)) ++ "' without signature? This should not happen!")
+ (Map.lookup (head sigs) entSignatures)
+ arg_name = mkVHDLExtId (bndrToString (last sigs))
+ dst_name = mkVHDLExtId (bndrToString bndr)
+ genSm = genBuilder 4 signature [arg_name, dst_name]
+ in return [AST.CSGSm genSm]
else
error $ "VHDL.mkConcSm Incorrect number of arguments to builtin function: " ++ pprString f ++ " Args: " ++ pprString valargs
Nothing -> error $ "Using function from another module that is not a known builtin: " ++ pprString f