From: Matthijs Kooijman Date: Thu, 19 Feb 2009 13:21:52 +0000 (+0100) Subject: Allow name hints to be set for a signal. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Fc%CE%BBash.git;a=commitdiff_plain;h=ee2454dbeb8d41d615726593acd8600c4a3253ae Allow name hints to be set for a signal. --- diff --git a/FlattenTypes.hs b/FlattenTypes.hs index 092baff..d007663 100644 --- a/FlattenTypes.hs +++ b/FlattenTypes.hs @@ -138,7 +138,8 @@ isInternalSigUse _ = False data SignalInfo = SignalInfo { sigName :: Maybe String, sigUse :: SigUse, - sigTy :: Type.Type + sigTy :: Type.Type, + nameHints :: [String] } -- | A flattened function @@ -183,10 +184,18 @@ genSignalId :: SigUse -> Type.Type -> FlattenState SignalId genSignalId use ty = do (defs, sigs, n) <- State.get -- Generate a new numbered but unnamed signal - let s = (n, SignalInfo Nothing use ty) + let s = (n, SignalInfo Nothing use ty []) State.put (defs, s:sigs, n+1) return n +-- | Add a name hint to the given signal +addNameHint :: SignalId -> String -> FlattenState () +addNameHint id hint = do + info <- getSignalInfo id + let hints = nameHints info + let hints' = (hint:hints) + setSignalInfo id (info {nameHints = hints'}) + -- | Returns the SignalInfo for the given signal. Errors if the signal is not -- known in the session. getSignalInfo :: SignalId -> FlattenState SignalInfo diff --git a/Pretty.hs b/Pretty.hs index cb1f9fc..433c15a 100644 --- a/Pretty.hs +++ b/Pretty.hs @@ -79,7 +79,7 @@ instance Pretty SignalExpr where parens $ pPrint a <> text " = " <> pPrint b instance Pretty SignalInfo where - pPrint (SignalInfo name use ty) = + pPrint (SignalInfo name use ty hints) = text ":" <> (pPrint use) <> (ppname name) where ppname Nothing = empty diff --git a/Translator.hs b/Translator.hs index 1a753c2..26cf79d 100644 --- a/Translator.hs +++ b/Translator.hs @@ -221,7 +221,7 @@ nameFlatFunction hsfunc fdata = -- Name the signals in all other functions Just flatfunc -> let s = flat_sigs flatfunc in - let s' = map (\(id, (SignalInfo Nothing use ty)) -> (id, SignalInfo (Just $ "sig_" ++ (show id)) use ty)) s in + let s' = map (\(id, (SignalInfo Nothing use ty hints)) -> (id, SignalInfo (Just $ "sig_" ++ (show id)) use ty hints)) s in let flatfunc' = flatfunc { flat_sigs = s' } in setFlatFunc hsfunc flatfunc'