X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FUtils%2FCore%2FCoreTools.hs;h=3ba262251c54131b6028b216e7ff248bc09eb18d;hb=2290559dd61c1cb5f16ef8fe3fc0fecccc29e792;hp=d8f4289d28b25253544126ba0424f90f6fc842de;hpb=10dfe589f40e65d51ca1585beecf00ae85169cae;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" index d8f4289..3ba2622 100644 --- "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" +++ "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" @@ -36,6 +36,7 @@ import qualified Unique import qualified CoreUtils import qualified CoreFVs import qualified Literal +import qualified MkCore -- Local imports import CLasH.Translator.TranslatorTypes @@ -298,6 +299,27 @@ hasStateType expr = case getType expr of Just ty -> isStateType ty +-- | Flattens nested non-recursive 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 :: + CoreSyn.CoreExpr -- ^ The expression to flatten. + -> ([Binding], CoreSyn.CoreExpr) -- ^ The bindings and resulting expression. +flattenLets (CoreSyn.Let (CoreSyn.NonRec bndr expr) res) = + ((bndr, expr):bindings, res') + where + -- Recursively flatten the contained expression + (bindings, res') = flattenLets res +flattenLets expr = ([], expr) + +-- | Create bunch of nested non-recursive let expressions from the given +-- bindings. The first binding is bound at the highest level (and thus +-- available in all other bindings). +mkNonRecLets :: [Binding] -> CoreSyn.CoreExpr -> CoreSyn.CoreExpr +mkNonRecLets bindings expr = MkCore.mkCoreLets binds expr + where + binds = map (uncurry CoreSyn.NonRec) bindings + -- | A class of things that (optionally) have a core Type. The type is -- optional, since Type expressions don't have a type themselves. class TypedThing t where