+cgTopBinding :: (StgBinding,[Id]) -> Code
+cgTopBinding (StgNonRec id rhs, srt)
+ = absC maybeSplitCode `thenC`
+ maybeGlobaliseId id `thenFC` \ id' ->
+ let
+ srt_label = mkSRTLabel (idName id')
+ in
+ mkSRT srt_label srt [] `thenC`
+ setSRTLabel srt_label (
+ cgTopRhs id' rhs `thenFC` \ (id, info) ->
+ addBindC id info
+ )
+
+cgTopBinding (StgRec pairs, srt)
+ = absC maybeSplitCode `thenC`
+ let
+ (bndrs, rhss) = unzip pairs
+ in
+ mapFCs maybeGlobaliseId bndrs `thenFC` \ bndrs'@(id:_) ->
+ let
+ srt_label = mkSRTLabel (idName id)
+ pairs' = zip bndrs' rhss
+ in
+ mkSRT srt_label srt bndrs' `thenC`
+ setSRTLabel srt_label (
+ fixC (\ new_binds ->
+ addBindsC new_binds `thenC`
+ mapFCs ( \ (b,e) -> cgTopRhs b e ) pairs'
+ ) `thenFC` \ new_binds -> nopC
+ )
+
+mkSRT :: CLabel -> [Id] -> [Id] -> Code
+mkSRT lbl [] these = nopC
+mkSRT lbl ids these
+ = mapFCs remap ids `thenFC` \ ids ->
+ absC (CSRT lbl (map (mkClosureLabel . idName) ids))
+ where
+ -- sigh, better map all the ids against the environment in case they've
+ -- been globalised (see maybeGlobaliseId below).
+ remap id = case filter (==id) these of
+ [] -> getCAddrModeAndInfo id
+ `thenFC` \ (id, _, _) -> returnFC id
+ (id':_) -> returnFC id'