X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=Flatten.hs;h=ee70446eaf5ed1b39ff56630b107a49f07fd1077;hb=1730303a697c4c35941919ada4e45e7a64803a7f;hp=3c5fda7b9537a801915b23ff0472720179127327;hpb=ec4c3ac86e30289a4eab441edc96a5d6556eeb57;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/Flatten.hs b/Flatten.hs index 3c5fda7..ee70446 100644 --- a/Flatten.hs +++ b/Flatten.hs @@ -22,12 +22,13 @@ data FlatFunction = FlatFunction { type SignalUseMap = HsValueMap SignalUse type SignalDefMap = HsValueMap SignalDef +type SignalId = Int data SignalUse = SignalUse { - sigUseId :: Int + sigUseId :: SignalId } deriving (Show, Eq) data SignalDef = SignalDef { - sigDefId :: Int + sigDefId :: SignalId } deriving (Show, Eq) data App = App { @@ -75,7 +76,26 @@ type BindMap = [( ) )] -type FlattenState = State.State ([App], [CondDef], Int) +type FlattenState = State.State ([App], [CondDef], SignalId) + +-- | Add an application to the current FlattenState +addApp :: App -> FlattenState () +addApp a = do + (apps, conds, n) <- State.get + State.put (a:apps, conds, n) + +-- | Add a conditional definition to the current FlattenState +addCondDef :: CondDef -> FlattenState () +addCondDef c = do + (apps, conds, n) <- State.get + State.put (apps, c:conds, n) + +-- | Generates a new signal id, which is unique within the current flattening. +genSignalId :: FlattenState SignalId +genSignalId = do + (apps, conds, n) <- State.get + State.put (apps, conds, n+1) + return n -- | Flatten a haskell function flattenFunction ::