From: Matthijs Kooijman Date: Fri, 13 Feb 2009 10:11:33 +0000 (+0100) Subject: Store signals in a map. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=9913c8098b3f42e404ee1b76c2ccd47f15769c64;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Store signals in a map. This turns the list of Signals into a list of (sigid, SignalInfo), which enables lookup by id. --- diff --git a/FlattenTypes.hs b/FlattenTypes.hs index b14ef38..7838dcd 100644 --- a/FlattenTypes.hs +++ b/FlattenTypes.hs @@ -75,8 +75,7 @@ data CondDef sigid = CondDef { } deriving (Show, Eq) -- | Information on a signal definition -data Signal sigid = Signal { - id :: sigid, +data SignalInfo = SignalInfo { name :: Maybe String } deriving (Eq, Show) @@ -86,7 +85,7 @@ data FlatFunction' sigid = FlatFunction { res :: SignalMap sigid, apps :: [FApp sigid], conds :: [CondDef sigid], - sigs :: [Signal sigid] + sigs :: [(sigid, SignalInfo)] } deriving (Show, Eq) -- | A flat function that does not have its signals named @@ -105,7 +104,7 @@ type BindMap = [( )] -- | The state during the flattening of a single function -type FlattenState = State.State ([FApp UnnamedSignal], [CondDef UnnamedSignal], [Signal UnnamedSignal], UnnamedSignal) +type FlattenState = State.State ([FApp UnnamedSignal], [CondDef UnnamedSignal], [(UnnamedSignal, SignalInfo)], UnnamedSignal) -- | Add an application to the current FlattenState addApp :: (FApp UnnamedSignal) -> FlattenState () @@ -124,6 +123,6 @@ genSignalId :: FlattenState UnnamedSignal genSignalId = do (apps, conds, sigs, n) <- State.get -- Generate a new numbered but unnamed signal - let s = Signal n Nothing + let s = (n, SignalInfo Nothing) State.put (apps, conds, s:sigs, n+1) return n diff --git a/Pretty.hs b/Pretty.hs index ee4b3be..d4ed8f0 100644 --- a/Pretty.hs +++ b/Pretty.hs @@ -42,9 +42,9 @@ instance Pretty id => Pretty (FApp id) where instance Pretty id => Pretty (CondDef id) where pPrint _ = text "TODO" -instance Pretty id => Pretty (Signal id) where - pPrint (Signal id Nothing) = pPrint id - pPrint (Signal id (Just name)) = pPrint id <> text ":" <> text name +instance Pretty SignalInfo where + pPrint (SignalInfo Nothing) = empty + pPrint (SignalInfo (Just name)) = text ":" <> text name instance Pretty VHDLSession where pPrint (VHDLSession mod nameCount funcs) = diff --git a/Translator.hs b/Translator.hs index bb5845b..6b96ebc 100644 --- a/Translator.hs +++ b/Translator.hs @@ -181,7 +181,7 @@ nameFlatFunction hsfunc 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 s' = map (\(id, (SignalInfo Nothing)) -> (id, SignalInfo (Just $ "sig_" ++ (show id)))) s in let flatfunc' = flatfunc { sigs = s' } in fdata { flatFunc = Just flatfunc' }