ae7dfc9bfd42f360fa70f0beb8526770dfc5c01f
[matthijs/master-project/cλash.git] / VHDL.hs
1 --
2 -- Functions to generate VHDL from FlatFunctions
3 --
4 module VHDL where
5
6 import Flatten
7 import qualified Type
8 import qualified Name
9 import qualified TyCon
10 import qualified Maybe
11 import Outputable ( showSDoc, ppr )
12 import qualified ForSyDe.Backend.VHDL.AST as AST
13
14
15 -- | The VHDL Bit type
16 bit_ty :: AST.TypeMark
17 bit_ty = AST.unsafeVHDLBasicId "Bit"
18
19 -- Translate a Haskell type to a VHDL type
20 vhdl_ty :: Type.Type -> AST.TypeMark
21 vhdl_ty ty = Maybe.fromMaybe
22   (error $ "Unsupported Haskell type: " ++ (showSDoc $ ppr ty))
23   (vhdl_ty_maybe ty)
24
25 -- Translate a Haskell type to a VHDL type
26 vhdl_ty_maybe :: Type.Type -> Maybe AST.TypeMark
27 vhdl_ty_maybe ty =
28   case Type.splitTyConApp_maybe ty of
29     Just (tycon, args) ->
30       let name = TyCon.tyConName tycon in
31         -- TODO: Do something more robust than string matching
32         case Name.getOccString name of
33           "Bit"      -> Just bit_ty
34           otherwise  -> Nothing
35     otherwise -> Nothing
36
37 -- Shortcut
38 mkVHDLId :: String -> AST.VHDLId
39 mkVHDLId = AST.unsafeVHDLBasicId
40