2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
4 \section[StgUtils]{Utility functions for @STG@ programs}
7 #include "HsVersions.h"
9 module StgUtils ( mapStgBindeesRhs ) where
13 import Id ( GenId{-instanced NamedThing-} )
18 This utility function simply applies the given function to every
19 bindee in the program.
22 mapStgBindeesBind :: (Id -> Id) -> StgBinding -> StgBinding
24 mapStgBindeesBind fn (StgNonRec b rhs) = StgNonRec b (mapStgBindeesRhs fn rhs)
25 mapStgBindeesBind fn (StgRec pairs) = StgRec [ (b, mapStgBindeesRhs fn r) | (b, r) <- pairs ]
28 mapStgBindeesRhs :: (Id -> Id) -> StgRhs -> StgRhs
30 mapStgBindeesRhs fn (StgRhsClosure cc bi fvs u args expr)
36 (mapStgBindeesExpr fn expr)
38 mapStgBindeesRhs fn (StgRhsCon cc con atoms)
39 = StgRhsCon cc con (map (mapStgBindeesArg fn) atoms)
42 mapStgBindeesExpr :: (Id -> Id) -> StgExpr -> StgExpr
44 mapStgBindeesExpr fn (StgApp f args lvs)
45 = StgApp (mapStgBindeesArg fn f)
46 (map (mapStgBindeesArg fn) args)
49 mapStgBindeesExpr fn (StgCon con atoms lvs)
50 = StgCon con (map (mapStgBindeesArg fn) atoms) (mapUniqSet fn lvs)
52 mapStgBindeesExpr fn (StgPrim op atoms lvs)
53 = StgPrim op (map (mapStgBindeesArg fn) atoms) (mapUniqSet fn lvs)
55 mapStgBindeesExpr fn (StgLet bind expr)
56 = StgLet (mapStgBindeesBind fn bind) (mapStgBindeesExpr fn expr)
58 mapStgBindeesExpr fn (StgLetNoEscape lvs rhss_lvs bind body)
59 = StgLetNoEscape (mapUniqSet fn lvs) (mapUniqSet fn rhss_lvs)
60 (mapStgBindeesBind fn bind) (mapStgBindeesExpr fn body)
62 mapStgBindeesExpr fn (StgSCC ty label expr)
63 = StgSCC ty label (mapStgBindeesExpr fn expr)
65 mapStgBindeesExpr fn (StgCase expr lvs1 lvs2 uniq alts)
66 = StgCase (mapStgBindeesExpr fn expr)
70 (mapStgBindeesAlts alts)
72 mapStgBindeesAlts (StgAlgAlts ty alts deflt)
73 = StgAlgAlts ty (map mapStgBindeesBoxed_alt alts) (mapStgBindeesDeflt deflt)
75 mapStgBindeesBoxed_alt (c,ps,use_mask,expr) = (c,ps,use_mask,mapStgBindeesExpr fn expr)
77 mapStgBindeesAlts (StgPrimAlts ty alts deflt)
78 = StgPrimAlts ty (map mapStgBindeesunboxed_alt alts) (mapStgBindeesDeflt deflt)
80 mapStgBindeesunboxed_alt (l,expr) = (l,mapStgBindeesExpr fn expr)
82 mapStgBindeesDeflt StgNoDefault = StgNoDefault
83 mapStgBindeesDeflt (StgBindDefault b used expr) = StgBindDefault b used (mapStgBindeesExpr fn expr)
86 mapStgBindeesArg :: (Id -> Id) -> StgArg -> StgArg
88 mapStgBindeesArg fn a@(StgLitArg _) = a
89 mapStgBindeesArg fn a@(StgVarArg id) = StgVarArg (fn id)