-\subsection[layOutDynClosure]{Lay out a dynamic closure}
-%* *
-%************************************************************************
-
-\begin{code}
-layOutDynClosure, layOutStaticClosure
- :: Name -- STG identifier of this closure
- -> (a -> PrimRep) -- how to get a PrimRep for the fields
- -> [a] -- the "things" being layed out
- -> LambdaFormInfo -- what sort of closure it is
- -> C_SRT
- -> (ClosureInfo, -- info about the closure
- [(a, VirtualHeapOffset)]) -- things w/ offsets pinned on them
-
-layOutDynClosure name kind_fn things lf_info srt_info
- = (MkClosureInfo { closureName = name, closureLFInfo = lf_info,
- closureSMRep = sm_rep, closureSRT = srt_info },
- things_w_offsets)
- where
- (tot_wds, -- #ptr_wds + #nonptr_wds
- ptr_wds, -- #ptr_wds
- things_w_offsets) = mkVirtHeapOffsets kind_fn things
- sm_rep = chooseDynSMRep lf_info tot_wds ptr_wds
-\end{code}
-
-Wrappers for when used with data constructors:
-
-\begin{code}
-layOutDynConstr, layOutStaticConstr
- :: Name -- Of the closure
- -> DataCon
- -> (a -> PrimRep) -> [a]
- -> (ClosureInfo, [(a,VirtualHeapOffset)])
-
-layOutDynConstr name data_con kind_fn args
- = layOutDynClosure name kind_fn args (mkConLFInfo data_con) NoC_SRT
-
-layOutStaticConstr name data_con kind_fn things
- = layOutStaticClosure name kind_fn things (mkConLFInfo data_con) NoC_SRT
-\end{code}
-
-%************************************************************************
-%* *
-\subsection[layOutStaticClosure]{Lay out a static closure}
-%* *
-%************************************************************************
-
-layOutStaticClosure is only used for laying out static constructors at
-the moment.
-
-Static closures for functions are laid out using
-layOutStaticNoFVClosure.
-
-\begin{code}
-layOutStaticClosure name kind_fn things lf_info srt_info
- = (MkClosureInfo { closureName = name, closureLFInfo = lf_info,
- closureSMRep = rep, closureSRT = srt_info },
- things_w_offsets)
- where
- rep = GenericRep is_static ptr_wds (tot_wds - ptr_wds) closure_type
-
- (tot_wds, -- #ptr_wds + #nonptr_wds
- ptr_wds, -- #ptr_wds
- things_w_offsets) = mkVirtHeapOffsets kind_fn things
-
- -- constructors with no pointer fields will definitely be NOCAF things.
- -- this is a compromise until we can generate both kinds of constructor
- -- (a normal static kind and the NOCAF_STATIC kind).
- closure_type = getClosureType is_static tot_wds ptr_wds lf_info
- is_static = True
-
-layOutStaticNoFVClosure :: Name -> LambdaFormInfo -> C_SRT -> ClosureInfo
-layOutStaticNoFVClosure name lf_info srt_info
- = MkClosureInfo { closureName = name, closureLFInfo = lf_info,
- closureSMRep = rep, closureSRT = srt_info }
- where
- rep = GenericRep is_static 0 0 (getClosureType is_static 0 0 lf_info)
- is_static = True
-
-
--- make a static closure, adding on any extra padding needed for CAFs,
--- and adding a static link field if necessary.
-
-mkStaticClosure closure_info ccs fields cafrefs
- | opt_SccProfilingOn =
- CStaticClosure
- closure_info
- (mkCCostCentreStack ccs)
- all_fields
- | otherwise =
- CStaticClosure
- closure_info
- (panic "absent cc")
- all_fields
-
- where
- all_fields = fields ++ padding_wds ++ static_link_field
-
- upd_reqd = closureUpdReqd closure_info
-
- padding_wds
- | not upd_reqd = []
- | otherwise = replicate n (mkIntCLit 0) -- a bunch of 0s
- where n = max 0 (mIN_UPD_SIZE - length fields)
-
- -- We always have a static link field for a thunk, it's used to
- -- save the closure's info pointer when we're reverting CAFs
- -- (see comment in Storage.c)
- static_link_field
- | upd_reqd || staticClosureNeedsLink closure_info = [static_link_value]
- | otherwise = []
-
- -- for a static constructor which has NoCafRefs, we set the
- -- static link field to a non-zero value so the garbage
- -- collector will ignore it.
- static_link_value
- | cafrefs = mkIntCLit 0
- | otherwise = mkIntCLit 1
-\end{code}
-
-%************************************************************************
-%* *