Store a use for each signal in a flattened function.
[matthijs/master-project/cλash.git] / FlattenTypes.hs
index 3389a5b6fdfed080cbbc84222b3e90187c7b46ef..5c95632859d22fc30a8752a28661ad6083eaf224 100644 (file)
@@ -4,6 +4,7 @@ import Data.Traversable
 import qualified Control.Monad.State as State
 
 import CoreSyn
+import qualified Type
 
 import HsValueMap
 
@@ -74,14 +75,28 @@ data CondDef sigid = CondDef {
   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,
+  sigUse  :: SigUse,
+  sigTy   :: Type.Type
+}
+
 -- | A flattened function
 data FlatFunction' sigid = FlatFunction {
-  args   :: [SignalMap sigid],
-  res    :: SignalMap sigid,
-  --sigs   :: [Signal],
-  apps   :: [FApp sigid],
-  conds  :: [CondDef sigid]
-} deriving (Show, Eq)
+  flat_args   :: [SignalMap sigid],
+  flat_res    :: SignalMap sigid,
+  flat_apps   :: [FApp sigid],
+  flat_conds  :: [CondDef sigid],
+  flat_sigs   :: [(sigid, SignalInfo)]
+}
 
 -- | A flat function that does not have its signals named
 type FlatFunction = FlatFunction' UnnamedSignal
@@ -99,24 +114,25 @@ 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], [(UnnamedSignal, SignalInfo)], 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)
+genSignalId :: SigUse -> Type.Type -> FlattenState UnnamedSignal 
+genSignalId use ty = do
+  (apps, conds, sigs, n) <- State.get
+  -- Generate a new numbered but unnamed signal
+  let s = (n, SignalInfo Nothing use ty)
+  State.put (apps, conds, s:sigs, n+1)
   return n
-