X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=Flatten.hs;h=f7ab86ce107ed770e6bbc46e3d67186e83eccdb9;hb=72a84356f5507b73d4d5f84844aac9334ee17795;hp=8a230162daf6f43cf21036390c6a072ae261ce8d;hpb=41e6a89a1d9347431e80b895cb74ab5ecc03e9b7;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/Flatten.hs b/Flatten.hs index 8a23016..f7ab86c 100644 --- a/Flatten.hs +++ b/Flatten.hs @@ -23,26 +23,27 @@ dataConAppArgs dc args = where tycount = length $ DataCon.dataConAllTyVars dc -genSignalUses :: +genSignals :: Type.Type - -> FlattenState SignalUseMap + -> FlattenState (SignalMap UnnamedSignal) -genSignalUses ty = do - typeMapToUseMap tymap +genSignals ty = do + typeMapToUseMap SigInternal tymap where -- First generate a map with the right structure containing the types tymap = mkHsValueMap ty typeMapToUseMap :: - HsValueMap Type.Type - -> FlattenState SignalUseMap + SigUse + -> HsValueMap Type.Type + -> FlattenState (SignalMap UnnamedSignal) -typeMapToUseMap (Single ty) = do - id <- genSignalId - return $ Single (SignalUse id) +typeMapToUseMap use (Single ty) = do + id <- genSignalId use ty + return $ Single id -typeMapToUseMap (Tuple tymaps) = do - usemaps <- State.mapM typeMapToUseMap tymaps +typeMapToUseMap use (Tuple tymaps) = do + usemaps <- State.mapM (typeMapToUseMap use) tymaps return $ Tuple usemaps -- | Flatten a haskell function @@ -53,26 +54,26 @@ flattenFunction :: flattenFunction _ (Rec _) = error "Recursive binders not supported" flattenFunction hsfunc bind@(NonRec var expr) = - FlatFunction args res apps conds + FlatFunction args res apps conds sigs where - init_state = ([], [], 0) + init_state = ([], [], [], 0) (fres, end_state) = State.runState (flattenExpr [] expr) init_state (args, res) = fres - (apps, conds, _) = end_state + (apps, conds, sigs, _) = end_state flattenExpr :: BindMap -> CoreExpr - -> FlattenState ([SignalDefMap], SignalUseMap) + -> FlattenState ([SignalMap UnnamedSignal], (SignalMap UnnamedSignal)) flattenExpr binds lam@(Lam b expr) = do -- Find the type of the binder let (arg_ty, _) = Type.splitFunTy (CoreUtils.exprType lam) -- Create signal names for the binder - defs <- genSignalUses arg_ty + defs <- genSignals arg_ty let binds' = (b, Left defs):binds (args, res) <- flattenExpr binds' expr - return ((useMapToDefMap defs) : args, res) + return (defs : args, res) flattenExpr binds (Var id) = case bind of @@ -114,12 +115,12 @@ flattenExpr binds app@(App _ _) = do -- Check and split each of the arguments let (_, arg_ress) = unzip (zipWith checkArg args flat_args) -- Generate signals for our result - res <- genSignalUses ty + res <- genSignals ty -- Create the function application let app = FApp { appFunc = func, appArgs = arg_ress, - appRes = useMapToDefMap res + appRes = res } addApp app return ([], res) @@ -154,7 +155,7 @@ flattenExpr binds expr@(Case (Var v) b _ alts) = -> Var.Var -- The scrutinee -> CoreBndr -- The binder to bind the scrutinee to -> CoreAlt -- The single alternative - -> FlattenState ( [SignalDefMap], SignalUseMap) + -> FlattenState ( [SignalMap UnnamedSignal], SignalMap UnnamedSignal) -- See expandExpr flattenSingleAltCaseExpr binds v b alt@(DataAlt datacon, bind_vars, expr) = if not (DataCon.isTupleCon datacon)