-> FlattenState (SignalMap UnnamedSignal)
genSignals ty = do
- typeMapToUseMap tymap
+ typeMapToUseMap SigInternal tymap
where
-- First generate a map with the right structure containing the types
tymap = mkHsValueMap ty
typeMapToUseMap ::
- HsValueMap Type.Type
+ SigUse
+ -> HsValueMap Type.Type
-> FlattenState (SignalMap UnnamedSignal)
-typeMapToUseMap (Single ty) = do
- id <- genSignalId ty
+typeMapToUseMap use (Single ty) = do
+ id <- genSignalId use ty
return $ Single id
-typeMapToUseMap (Tuple tymaps) = do
- usemaps <- State.mapM typeMapToUseMap tymaps
+typeMapToUseMap use (Tuple tymaps) = do
+ usemaps <- State.mapM (typeMapToUseMap use) tymaps
return $ Tuple usemaps
-- | Flatten a haskell function
condRes :: sigid
} deriving (Show, Eq)
+-- | How is a given signal used in the resulting VHDL?
+data SigUse =
+ SigPort -- | Use as a port
+ | SigInternal -- | Use as an internal signal
+ | SigState -- | Use as an internal state
+ | SigSubState -- | Do not use, state variable is used in a subcircuit
+
-- | Information on a signal definition
data SignalInfo = SignalInfo {
sigName :: Maybe String,
+ sigUse :: SigUse,
sigTy :: Type.Type
}
State.put (apps, c:conds, sigs, n)
-- | Generates a new signal id, which is unique within the current flattening.
-genSignalId :: Type.Type -> FlattenState UnnamedSignal
-genSignalId ty = do
+genSignalId :: SigUse -> Type.Type -> FlattenState UnnamedSignal
+genSignalId use ty = do
(apps, conds, sigs, n) <- State.get
-- Generate a new numbered but unnamed signal
- let s = (n, SignalInfo Nothing ty)
+ let s = (n, SignalInfo Nothing use ty)
State.put (apps, conds, s:sigs, n+1)
return n
pPrint _ = text "TODO"
instance Pretty SignalInfo where
- pPrint (SignalInfo Nothing ty) = empty
- pPrint (SignalInfo (Just name) ty) = text ":" <> text name
+ pPrint (SignalInfo name use ty) =
+ text ":" <> (pPrint use) <> (ppname name)
+ where
+ ppname Nothing = empty
+ ppname (Just name) = text ":" <> text name
+
+instance Pretty SigUse where
+ pPrint SigPort = text "P"
+ pPrint SigInternal = text "I"
+ pPrint SigState = text "S"
+ pPrint SigSubState = text "s"
instance Pretty VHDLSession where
pPrint (VHDLSession mod nameCount funcs) =
-- Name the signals in all other functions
Just flatfunc ->
let s = flat_sigs flatfunc in
- let s' = map (\(id, (SignalInfo Nothing ty)) -> (id, SignalInfo (Just $ "sig_" ++ (show id)) ty)) s in
+ let s' = map (\(id, (SignalInfo Nothing use ty)) -> (id, SignalInfo (Just $ "sig_" ++ (show id)) use ty)) s in
let flatfunc' = flatfunc { flat_sigs = s' } in
setFlatFunc hsfunc flatfunc'