2 -- Functions to generate VHDL from FlatFunctions
6 import Data.Traversable
11 import qualified TyCon
12 import Outputable ( showSDoc, ppr )
14 import qualified ForSyDe.Backend.VHDL.AST as AST
18 import TranslatorTypes
20 -- | Create an entity for a given function
22 HsFunction -- | The function signature
23 -> FuncData -- | The function data collected so far
24 -> FuncData -- | The modified function data
26 createEntity hsfunc fdata =
27 let func = flatFunc fdata in
29 -- Skip (builtin) functions without a FlatFunction
31 -- Create an entity for all other functions
38 args' = map (fmap (mkMap s)) a
39 res' = fmap (mkMap s) r
40 entity' = Entity args' res' Nothing
42 fdata { entity = Just entity' }
44 mkMap :: Eq id => [(id, SignalInfo)] -> id -> AST.VHDLId
48 info = Maybe.fromMaybe
49 (error $ "Signal not found in the name map? This should not happen!")
52 (error $ "Signal not named? This should not happen!")
59 -- | The VHDL Bit type
60 bit_ty :: AST.TypeMark
61 bit_ty = AST.unsafeVHDLBasicId "Bit"
63 -- Translate a Haskell type to a VHDL type
64 vhdl_ty :: Type.Type -> AST.TypeMark
65 vhdl_ty ty = Maybe.fromMaybe
66 (error $ "Unsupported Haskell type: " ++ (showSDoc $ ppr ty))
69 -- Translate a Haskell type to a VHDL type
70 vhdl_ty_maybe :: Type.Type -> Maybe AST.TypeMark
72 case Type.splitTyConApp_maybe ty of
74 let name = TyCon.tyConName tycon in
75 -- TODO: Do something more robust than string matching
76 case Name.getOccString name of
82 mkVHDLId :: String -> AST.VHDLId
83 mkVHDLId = AST.unsafeVHDLBasicId