-- | Information on a signal definition
data Signal sigid = Signal {
- id :: sigid
+ id :: sigid,
+ name :: Maybe String
} deriving (Eq, Show)
-- | A flattened function
genSignalId :: FlattenState UnnamedSignal
genSignalId = do
(apps, conds, sigs, n) <- State.get
- let s = Signal n
+ -- Generate a new numbered but unnamed signal
+ let s = Signal n Nothing
State.put (apps, conds, s:sigs, n+1)
return n
pPrint _ = text "TODO"
instance Pretty id => Pretty (Signal id) where
- pPrint (Signal id) = pPrint id
+ pPrint (Signal id Nothing) = pPrint id
+ pPrint (Signal id (Just name)) = pPrint id <> text ":" <> text name
instance Pretty VHDLSession where
pPrint (VHDLSession mod nameCount funcs) =
mapM addBuiltIn builtin_funcs
-- Create entities and architectures for them
mapM processBind binds
+ modFuncs nameFlatFunction
return $ AST.DesignFile
[]
[]
error $ "Input state type of function " ++ hsname ++ ": " ++ (showSDoc $ ppr state_ty) ++ " does not match output state type: " ++ (showSDoc $ ppr outstate_ty)
otherwise -> error $ "Return type of top-level function " ++ hsname ++ " must be a two-tuple containing a state and output ports."
+-- | Adds signal names to the given FlatFunction
+nameFlatFunction ::
+ HsFunction
+ -> FuncData
+ -> FuncData
+
+nameFlatFunction hsfunc fdata =
+ let func = flatFunc fdata in
+ case func of
+ -- Skip (builtin) functions without a FlatFunction
+ Nothing -> fdata
+ -- Name the signals in all other functions
+ Just flatfunc ->
+ let s = sigs flatfunc in
+ let s' = map (\(Signal id Nothing) -> Signal id (Just $ "sig_" ++ (show id))) s in
+ let flatfunc' = flatfunc { sigs = s' } in
+ fdata { flatFunc = Just flatfunc' }
+
-- | Splits a tuple type into a list of element types, or Nothing if the type
-- is not a tuple type.
splitTupleType ::
let fs'= Map.adjust (\d -> d { flatFunc = Just flatfunc }) hsfunc fs
State.modify (\x -> x {funcs = fs' })
-modFunc :: HsFunction -> (HsFunction -> FuncData -> FuncData) -> VHDLState ()
-modFunc hsfunc f = do
+-- | Modify all functions in the map using the given function
+modFuncs :: (HsFunction -> FuncData -> FuncData) -> VHDLState ()
+modFuncs f = do
fs <- State.gets funcs -- Get the funcs element from the session
- let fs' = Map.adjustWithKey f hsfunc fs
+ let fs' = Map.mapWithKey f fs
State.modify (\x -> x {funcs = fs' })
getModule :: VHDLState HscTypes.CoreModule