Remove NamedFlatFunction again.
[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 -- | The VHDL Bit type
15 bit_ty :: AST.TypeMark
16 bit_ty = AST.unsafeVHDLBasicId "Bit"
17
18 -- Translate a Haskell type to a VHDL type
19 vhdl_ty :: Type.Type -> AST.TypeMark
20 vhdl_ty ty = Maybe.fromMaybe
21   (error $ "Unsupported Haskell type: " ++ (showSDoc $ ppr ty))
22   (vhdl_ty_maybe ty)
23
24 -- Translate a Haskell type to a VHDL type
25 vhdl_ty_maybe :: Type.Type -> Maybe AST.TypeMark
26 vhdl_ty_maybe ty =
27   case Type.splitTyConApp_maybe ty of
28     Just (tycon, args) ->
29       let name = TyCon.tyConName tycon in
30         -- TODO: Do something more robust than string matching
31         case Name.getOccString name of
32           "Bit"      -> Just bit_ty
33           otherwise  -> Nothing
34     otherwise -> Nothing
35
36 -- Shortcut
37 mkVHDLId :: String -> AST.VHDLId
38 mkVHDLId = AST.unsafeVHDLBasicId