Add predicates for SigUse.
[matthijs/master-project/cλash.git] / FlattenTypes.hs
index e7d21d605c5fec8901e9ad104cb4f92f8f3c3849..9f080f70666eec1755c8df1897b4c5ff507222f8 100644 (file)
@@ -1,5 +1,6 @@
 module FlattenTypes where
 
+import qualified Maybe
 import Data.Traversable
 import qualified Data.Foldable as Foldable
 import qualified Control.Monad.State as State
@@ -88,10 +89,29 @@ data CondDef sigid = CondDef {
 
 -- | 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
+  SigPortIn          -- | Use as an input port
+  | SigPortOut       -- | Use as an input port
+  | SigInternal      -- | Use as an internal signal
+  | SigStateOld Int  -- | Use as the current internal state
+  | SigStateNew Int  -- | Use as the new internal state
+  | SigSubState      -- | Do not use, state variable is used in a subcircuit
+
+-- | Is this a port signal use?
+isPortSigUse :: SigUse -> Bool
+isPortSigUse SigPortIn = True
+isPortSigUse SigPortOut = True
+isPortSigUse _ = False
+
+-- | Is this a state signal use? Returns false for substate.
+isStateSigUse :: SigUse -> Bool
+isStateSigUse (SigStateOld _) = True
+isStateSigUse (SigStateNew _) = True
+isStateSigUse _ = False
+
+-- | Is this an internal signal use?
+isInternalSigUse :: SigUse -> Bool
+isInternalSigUse SigInternal = True
+isInternalSigUse _ = False
 
 -- | Information on a signal definition
 data SignalInfo = SignalInfo {
@@ -109,6 +129,11 @@ data FlatFunction' sigid = FlatFunction {
   flat_sigs   :: [(sigid, SignalInfo)]
 }
 
+-- | Lookup a given signal id in a signal map, and return the associated
+--   SignalInfo. Errors out if the signal was not found.
+signalInfo :: Eq sigid => [(sigid, SignalInfo)] -> sigid -> SignalInfo
+signalInfo sigs id = Maybe.fromJust $ lookup id sigs
+
 -- | A flat function that does not have its signals named
 type FlatFunction = FlatFunction' UnnamedSignal