Allow a FlatFunction to be named as well as unnamed.
[matthijs/master-project/cλash.git] / FlattenTypes.hs
index 3389a5b6fdfed080cbbc84222b3e90187c7b46ef..024db9b5332c6f4d94a22b356ed697d966ab70b8 100644 (file)
@@ -74,13 +74,18 @@ data CondDef sigid = CondDef {
   condRes :: sigid
 } deriving (Show, Eq)
 
+-- | Information on a signal definition
+data Signal sigid = Signal {
+  id :: sigid
+} deriving (Eq, Show)
+
 -- | A flattened function
 data FlatFunction' sigid = FlatFunction {
   args   :: [SignalMap sigid],
   res    :: SignalMap sigid,
-  --sigs   :: [Signal],
   apps   :: [FApp sigid],
-  conds  :: [CondDef sigid]
+  conds  :: [CondDef sigid],
+  sigs   :: [Signal sigid]
 } deriving (Show, Eq)
 
 -- | A flat function that does not have its signals named
@@ -99,24 +104,24 @@ type BindMap = [(
   )]
 
 -- | The state during the flattening of a single function
-type FlattenState = State.State ([FApp UnnamedSignal], [CondDef UnnamedSignal], UnnamedSignal)
+type FlattenState = State.State ([FApp UnnamedSignal], [CondDef UnnamedSignal], [Signal UnnamedSignal], UnnamedSignal)
 
 -- | Add an application to the current FlattenState
 addApp :: (FApp UnnamedSignal) -> FlattenState ()
 addApp a = do
-  (apps, conds, n) <- State.get
-  State.put (a:apps, conds, n)
+  (apps, conds, sigs, n) <- State.get
+  State.put (a:apps, conds, sigs, n)
 
 -- | Add a conditional definition to the current FlattenState
 addCondDef :: (CondDef UnnamedSignal) -> FlattenState ()
 addCondDef c = do
-  (apps, conds, n) <- State.get
-  State.put (apps, c:conds, n)
+  (apps, conds, sigs, n) <- State.get
+  State.put (apps, c:conds, sigs, n)
 
 -- | Generates a new signal id, which is unique within the current flattening.
 genSignalId :: FlattenState UnnamedSignal 
 genSignalId = do
-  (apps, conds, n) <- State.get
-  State.put (apps, conds, n+1)
+  (apps, conds, sigs, n) <- State.get
+  let s = Signal n
+  State.put (apps, conds, s:sigs, n+1)
   return n
-