X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FNormalize.hs;h=1d40f92d52f7b94989fc9215bcfd15723a9001e0;hb=51a7bd0bb429d112154578fdd1dfd706e6e01f6e;hp=7fb0dc235d2a60d8a3e3798b8a655e9f6f3218f7;hpb=10dfe589f40e65d51ca1585beecf00ae85169cae;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Normalize.hs" "b/c\316\273ash/CLasH/Normalize.hs" index 7fb0dc2..1d40f92 100644 --- "a/c\316\273ash/CLasH/Normalize.hs" +++ "b/c\316\273ash/CLasH/Normalize.hs" @@ -595,9 +595,25 @@ getBinding bndr = Utils.makeCached bndr tsBindings $ do splitNormalized :: CoreExpr -- ^ The normalized expression -> ([CoreBndr], [Binding], CoreBndr) -splitNormalized expr = - case letexpr of - (Let (Rec binds) (Var res)) -> (args, binds, res) - _ -> error $ "Normalize.splitNormalized: Not in normal form: " ++ pprString expr ++ "\n" +splitNormalized expr = (args, binds, res) where (args, letexpr) = CoreSyn.collectBinders expr + (binds, resexpr) = flattenLets letexpr + res = case resexpr of + (Var x) -> x + _ -> error $ "Normalize.splitNormalized: Not in normal form: " ++ pprString expr ++ "\n" + +-- | Flattens nested lets into a single list of bindings. The expression +-- passed does not have to be a let expression, if it isn't an empty list of +-- bindings is returned. +flattenLets :: + CoreExpr -- ^ The expression to flatten. + -> ([Binding], CoreExpr) -- ^ The bindings and resulting expression. +flattenLets (Let binds expr) = + (bindings ++ bindings', expr') + where + -- Recursively flatten the contained expression + (bindings', expr') =flattenLets expr + -- Flatten our own bindings to remove the Rec / NonRec constructors + bindings = CoreSyn.flattenBinds [binds] +flattenLets expr = ([], expr)