-cgTopBindings :: AbstractC -> [(StgBinding,[Id])] -> Code
-
-cgTopBindings split bindings = mapCs (cgTopBinding split) bindings
-
-cgTopBinding :: AbstractC -> (StgBinding,[Id]) -> Code
-
-cgTopBinding split ((StgNonRec name rhs), srt)
- = absC split `thenC`
- absC (mkSRT srt_label srt) `thenC`
- setSRTLabel srt_label (
- cgTopRhs name rhs `thenFC` \ (name, info) ->
- addBindC name info
- )
- where
- srt_label = mkSRTLabel (idName name)
-
-cgTopBinding split ((StgRec pairs@((name,rhs):_)), srt)
- = absC split `thenC`
- absC (mkSRT srt_label srt) `thenC`
- setSRTLabel srt_label (
- fixC (\ new_binds -> addBindsC new_binds `thenC`
- mapFCs ( \ (b,e) -> cgTopRhs b e ) pairs
- ) `thenFC` \ new_binds ->
- addBindsC new_binds
- )
+cgTopBinding :: (StgBinding,[(Id,[Id])]) -> Code
+cgTopBinding (StgNonRec id rhs, srts)
+ = absC maybeSplitCode `thenC`
+ maybeExternaliseId id `thenFC` \ id' ->
+ mapM_ (mkSRT [id']) srts `thenC`
+ cgTopRhs id' rhs `thenFC` \ (id, info) ->
+ addBindC id info `thenC`
+ -- Add the un-externalised Id to the envt, so we
+ -- find it when we look up occurrences
+ nopC
+
+cgTopBinding (StgRec pairs, srts)
+ = absC maybeSplitCode `thenC`
+ let
+ (bndrs, rhss) = unzip pairs
+ in
+ mapFCs maybeExternaliseId bndrs `thenFC` \ bndrs' ->
+ let
+ pairs' = zip bndrs' rhss
+ in
+ mapM_ (mkSRT bndrs') srts `thenC`
+ fixC (\ new_binds ->
+ addBindsC new_binds `thenC`
+ mapFCs ( \ (b,e) -> cgTopRhs b e ) pairs'
+ ) `thenFC` \ new_binds ->
+ nopC
+
+mkSRT :: [Id] -> (Id,[Id]) -> Code
+mkSRT these (id,[]) = nopC
+mkSRT these (id,ids)
+ = mapFCs remap ids `thenFC` \ ids ->
+ remap id `thenFC` \ id ->
+ absC (CSRT (mkSRTLabel (idName id)) (map (mkClosureLabel . idName) ids))