From: Matthijs Kooijman Date: Thu, 18 Jun 2009 12:47:56 +0000 (+0200) Subject: Add a substitute helper function. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=56c7e95a268187a0dd4aea1fa9e669755247c79b;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Add a substitute helper function. This function performs a number of substitutions on a CoreExpr, by using the CoreSubst module. --- diff --git a/NormalizeTools.hs b/NormalizeTools.hs index 91e5b45..193af61 100644 --- a/NormalizeTools.hs +++ b/NormalizeTools.hs @@ -23,6 +23,7 @@ import qualified SrcLoc import qualified Type import qualified IdInfo import qualified CoreUtils +import qualified CoreSubst import Outputable ( showSDoc, ppr, nest ) -- Local imports @@ -140,3 +141,9 @@ mkUnique = Trans.lift $ do let (us', us'') = UniqSupply.splitUniqSupply us putA tsUniqSupply us' return $ UniqSupply.uniqFromSupply us'' + +-- Replace each of the binders given with the coresponding expressions in the +-- given expression. +substitute :: [(CoreBndr, CoreExpr)] -> CoreExpr -> CoreExpr +substitute replace expr = CoreSubst.substExpr subs expr + where subs = foldl (\s (b, e) -> CoreSubst.extendIdSubst s b e) CoreSubst.emptySubst replace