2 -- Some types used by the VHDL module.
4 {-# LANGUAGE TemplateHaskell, NoGenerics #-}
5 module CLasH.VHDL.VHDLTypes where
8 import qualified Control.Monad.Trans.State as State
9 import qualified Data.Map as Map
11 import qualified Data.Accessor.Template
15 import qualified CoreSyn
16 import qualified HscTypes
19 import qualified Language.VHDL.AST as AST
23 -- A description of a port of an entity
24 type Port = (AST.VHDLId, AST.TypeMark)
26 -- A description of a VHDL entity. Contains both the entity itself as well as
27 -- info on how to map a haskell value (argument / result) on to the entity's
29 data Entity = Entity {
30 ent_id :: AST.VHDLId, -- The id of the entity
31 ent_args :: [Port], -- A mapping of each function argument to port names
32 ent_res :: Port -- A mapping of the function result to port names
35 -- A orderable equivalent of CoreSyn's Type for use as a map key
36 newtype OrdType = OrdType { getType :: Type.Type }
37 instance Eq OrdType where
38 (OrdType a) == (OrdType b) = Type.tcEqType a b
39 instance Ord OrdType where
40 compare (OrdType a) (OrdType b) = Type.tcCmpType a b
42 data HType = StdType OrdType |
43 ADTType String [HType] |
51 -- A map of a Core type to the corresponding type name
52 type TypeMap = Map.Map HType (AST.VHDLId, Either AST.TypeDef AST.SubtypeIn)
54 -- A map of a vector Core element type and function name to the coressponding
55 -- VHDLId of the function and the function body.
56 type TypeFunMap = Map.Map (OrdType, String) (AST.VHDLId, AST.SubProgBody)
58 -- A map of a Haskell function to a hardware signature
59 type SignatureMap = Map.Map CoreSyn.CoreBndr Entity
61 type TfpIntMap = Map.Map OrdType Int
63 data TypeState = TypeState {
64 -- | A map of Core type -> VHDL Type
66 -- | A list of type declarations
67 vsTypeDecls_ :: [AST.PackageDecItem],
68 -- | A map of vector Core type -> VHDL type function
69 vsTypeFuns_ :: TypeFunMap,
70 vsTfpInts_ :: TfpIntMap,
71 vsHscEnv_ :: HscTypes.HscEnv
74 $( Data.Accessor.Template.deriveAccessors ''TypeState )
76 type TypeSession = State.State TypeState
78 data VHDLState = VHDLState {
79 -- | A subtype with typing info
81 -- | A map of HsFunction -> hardware signature (entity name, port names,
83 vsSignatures_ :: SignatureMap
87 $( Data.Accessor.Template.deriveAccessors ''VHDLState )
89 -- | The state containing a VHDL Session
90 type VHDLSession = State.State VHDLState
92 -- A function that generates VHDL for a builtin function
94 (Either CoreSyn.CoreBndr AST.VHDLName) -- ^ The destination signal and it's original type
95 -> CoreSyn.CoreBndr -- ^ The function called
96 -> [Either CoreSyn.CoreExpr AST.Expr] -- ^ The value arguments passed (excluding type and
97 -- dictionary arguments).
98 -> VHDLSession [AST.ConcSm] -- ^ The resulting concurrent statements.
100 -- A map of a builtin function to VHDL function builder
101 type NameTable = Map.Map String (Int, BuiltinBuilder )
103 -- vim: set ts=8 sw=2 sts=2 expandtab: