This allows us to differentiate between ports, signals and states more
easily (which is already possible but not so easy right now) and allows
us to differentiate between own state and substate later on.
Currently, all signals are marked as SigInternal.
-> FlattenState (SignalMap UnnamedSignal)
genSignals ty = do
-> FlattenState (SignalMap UnnamedSignal)
genSignals ty = do
+ typeMapToUseMap SigInternal tymap
where
-- First generate a map with the right structure containing the types
tymap = mkHsValueMap ty
typeMapToUseMap ::
where
-- First generate a map with the right structure containing the types
tymap = mkHsValueMap ty
typeMapToUseMap ::
+ SigUse
+ -> HsValueMap Type.Type
-> FlattenState (SignalMap UnnamedSignal)
-> FlattenState (SignalMap UnnamedSignal)
-typeMapToUseMap (Single ty) = do
- id <- genSignalId ty
+typeMapToUseMap use (Single ty) = do
+ id <- genSignalId use ty
-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
return $ Tuple usemaps
-- | Flatten a haskell function
condRes :: sigid
} deriving (Show, Eq)
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,
-- | Information on a signal definition
data SignalInfo = SignalInfo {
sigName :: Maybe String,
State.put (apps, c:conds, sigs, n)
-- | Generates a new signal id, which is unique within the current flattening.
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
(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
State.put (apps, conds, s:sigs, n+1)
return n
pPrint _ = text "TODO"
instance Pretty SignalInfo where
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) =
instance Pretty VHDLSession where
pPrint (VHDLSession mod nameCount funcs) =
-- Name the signals in all other functions
Just flatfunc ->
let s = flat_sigs flatfunc in
-- 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'
let flatfunc' = flatfunc { flat_sigs = s' } in
setFlatFunc hsfunc flatfunc'