a5d1569eb5728ebce6ec43223f5446674383bf9e
[matthijs/master-project/cλash.git] / VHDLTypes.hs
1 --
2 -- Some types used by the VHDL module.
3 --
4 {-# LANGUAGE TemplateHaskell #-}
5 module VHDLTypes where
6
7 -- Standard imports
8 import qualified Control.Monad.Trans.State as State
9 import qualified Data.Map as Map
10 import Data.Accessor
11 import qualified Data.Accessor.Template
12
13 -- GHC API imports
14 import qualified Type
15
16 -- ForSyDe imports
17 import qualified ForSyDe.Backend.VHDL.AST as AST
18
19 -- Local imports
20 import FlattenTypes
21 import HsValueMap
22
23 type VHDLSignalMapElement = (Maybe (AST.VHDLId, AST.TypeMark))
24 -- | A mapping from a haskell structure to the corresponding VHDL port
25 --   signature, or Nothing for values that do not translate to a port.
26 type VHDLSignalMap = HsValueMap VHDLSignalMapElement
27
28 -- A description of a VHDL entity. Contains both the entity itself as well as
29 -- info on how to map a haskell value (argument / result) on to the entity's
30 -- ports.
31 data Entity = Entity { 
32   ent_id     :: AST.VHDLId,           -- The id of the entity
33   ent_args   :: [VHDLSignalMap],      -- A mapping of each function argument to port names
34   ent_res    :: VHDLSignalMap         -- A mapping of the function result to port names
35 } deriving (Show);
36
37 -- A orderable equivalent of CoreSyn's Type for use as a map key
38 newtype OrdType = OrdType { getType :: Type.Type }
39 instance Eq OrdType where
40   (OrdType a) == (OrdType b) = Type.tcEqType a b
41 instance Ord OrdType where
42   compare (OrdType a) (OrdType b) = Type.tcCmpType a b
43
44 -- A map of a Core type to the corresponding type name
45 type TypeMap = Map.Map OrdType (AST.VHDLId, AST.TypeDec)
46
47 -- A map of a Haskell function to a hardware signature
48 type SignatureMap = Map.Map HsFunction Entity
49
50 -- A map of a builtin function to VHDL function builder 
51 type NameTable = Map.Map String (Int, [AST.Expr] -> AST.Expr )
52
53 data VHDLSession = VHDLSession {
54   -- | A map of Core type -> VHDL Type
55   vsTypes_ :: TypeMap,
56   -- | A map of HsFunction -> hardware signature (entity name, port names,
57   --   etc.)
58   vsSignatures_ :: SignatureMap
59 }
60
61 -- Derive accessors
62 $( Data.Accessor.Template.deriveAccessors ''VHDLSession )
63
64 -- | The state containing a VHDL Session
65 type VHDLState = State.State VHDLSession
66
67 -- | A substate containing just the types
68 type TypeState = State.State TypeMap
69
70 -- vim: set ts=8 sw=2 sts=2 expandtab: