%
+% (c) The University of Glasgow 2006
% (c) The GRASP Project, Glasgow University, 1992-1998
%
\section[CgCon]{Code generation for constructors}
import CgMonad
import StgSyn
-import CgBindery ( getArgAmodes, bindNewToNode,
- bindArgsToRegs, idInfoToAmode, stableIdInfo,
- heapIdInfo, CgIdInfo, bindArgsToStack
- )
-import CgStackery ( mkVirtStkOffsets, freeStackSlots,
- getRealSp, getVirtSp, setRealAndVirtualSp )
-import CgUtils ( addIdReps, cmmLabelOffW, emitRODataLits, emitDataLits )
-import CgCallConv ( assignReturnRegs )
-import Constants ( mAX_INTLIKE, mIN_INTLIKE, mAX_CHARLIKE, mIN_CHARLIKE )
-import CgHeapery ( allocDynClosure, layOutDynConstr,
- layOutStaticConstr, mkStaticClosureFields )
-import CgTailCall ( performReturn, emitKnownConReturnCode, returnUnboxedTuple )
-import CgProf ( mkCCostCentreStack, ldvEnter, curCCS )
+import CgBindery
+import CgStackery
+import CgUtils
+import CgCallConv
+import CgHeapery
+import CgTailCall
+import CgProf
import CgTicky
-import CgInfoTbls ( emitClosureCodeAndInfoTable, dataConTagZ )
+import CgInfoTbls
import CLabel
-import ClosureInfo ( mkConLFInfo, mkLFArgument )
-import CmmUtils ( mkLblExpr )
+import ClosureInfo
+import CmmUtils
import Cmm
-import SMRep ( WordOff, CgRep, separateByPtrFollowness,
- fixedHdrSize, typeCgRep )
-import CostCentre ( currentOrSubsumedCCS, dontCareCCS, CostCentreStack,
- currentCCS )
-import Constants ( mIN_INTLIKE, mAX_INTLIKE, mIN_CHARLIKE, mAX_CHARLIKE )
-import TyCon ( TyCon, tyConDataCons, isEnumerationTyCon, tyConName )
-import DataCon ( DataCon, dataConRepArgTys, isNullaryRepDataCon,
- isUnboxedTupleCon, dataConWorkId,
- dataConName, dataConRepArity
- )
-import Id ( Id, idName, isDeadBinder )
-import Type ( Type )
-import PrelInfo ( maybeCharLikeCon, maybeIntLikeCon )
+import SMRep
+import CostCentre
+import Constants
+import TyCon
+import DataCon
+import Id
+import Type
+import PrelInfo
import Outputable
-import Util ( lengthIs )
-import ListSetOps ( assocMaybe )
+import Util
+import ListSetOps
\end{code}
-> FCode (Id, CgIdInfo)
cgTopRhsCon id con args
= do {
- ; hmods <- getHomeModules
+ ; this_pkg <- getThisPackage
#if mingw32_TARGET_OS
-- Windows DLLs have a problem with static cross-DLL refs.
- ; ASSERT( not (isDllConApp hmods con args) ) return ()
+ ; ASSERT( not (isDllConApp this_pkg con args) ) return ()
#endif
; ASSERT( args `lengthIs` dataConRepArity con ) return ()
; let
name = idName id
lf_info = mkConLFInfo con
- closure_label = mkClosureLabel hmods name
+ closure_label = mkClosureLabel this_pkg name
caffy = any stgArgHasCafRefs args
- (closure_info, amodes_w_offsets) = layOutStaticConstr hmods con amodes
+ (closure_info, amodes_w_offsets) = layOutStaticConstr this_pkg con amodes
closure_rep = mkStaticClosureFields
closure_info
dontCareCCS -- Because it's static data
\begin{code}
buildDynCon binder cc con []
- = do hmods <- getHomeModules
+ = do this_pkg <- getThisPackage
returnFC (stableIdInfo binder
- (mkLblExpr (mkClosureLabel hmods (dataConName con)))
+ (mkLblExpr (mkClosureLabel this_pkg (dataConName con)))
(mkConLFInfo con))
\end{code}
\begin{code}
buildDynCon binder ccs con args
= do {
- ; hmods <- getHomeModules
+ ; this_pkg <- getThisPackage
; let
- (closure_info, amodes_w_offsets) = layOutDynConstr hmods con args
+ (closure_info, amodes_w_offsets) = layOutDynConstr this_pkg con args
; hp_off <- allocDynClosure closure_info use_cc blame_cc amodes_w_offsets
; returnFC (heapIdInfo binder hp_off lf_info) }
\begin{code}
bindConArgs :: DataCon -> [Id] -> Code
bindConArgs con args
- = do hmods <- getHomeModules
+ = do this_pkg <- getThisPackage
let
bind_arg (arg, offset) = bindNewToNode arg offset (mkLFArgument arg)
- (_, args_w_offsets) = layOutDynConstr hmods con (addIdReps args)
+ (_, args_w_offsets) = layOutDynConstr this_pkg con (addIdReps args)
--
ASSERT(not (isUnboxedTupleCon con)) return ()
mapCs bind_arg args_w_offsets
= ASSERT( amodes `lengthIs` dataConRepArity con )
do { EndOfBlockInfo _ sequel <- getEndOfBlockInfo
; case sequel of
- CaseAlts _ (Just (alts, deflt_lbl)) bndr _
+ CaseAlts _ (Just (alts, deflt_lbl)) bndr
-> -- Ho! We know the constructor so we can
-- go straight to the right alternative
case assocMaybe alts (dataConTagZ con) of {
other_sequel -- The usual case
| isUnboxedTupleCon con -> returnUnboxedTuple amodes
- | otherwise -> build_it_then (emitKnownConReturnCode con)
+ | otherwise -> build_it_then emitReturnInstr
}
where
jump_to lbl = stmtC (CmmJump (CmmLit lbl) [])
cgDataCon :: DataCon -> Code
cgDataCon data_con
= do { -- Don't need any dynamic closure code for zero-arity constructors
- hmods <- getHomeModules
+ this_pkg <- getThisPackage
; let
-- To allow the debuggers, interpreters, etc to cope with
-- time), we take care that info-table contains the
-- information we need.
(static_cl_info, _) =
- layOutStaticConstr hmods data_con arg_reps
+ layOutStaticConstr this_pkg data_con arg_reps
(dyn_cl_info, arg_things) =
- layOutDynConstr hmods data_con arg_reps
+ layOutDynConstr this_pkg data_con arg_reps
emit_info cl_info ticky_code
= do { code_blks <- getCgStmts the_code
body_code = do {
-- NB: We don't set CC when entering data (WDP 94/06)
tickyReturnOldCon (length arg_things)
- ; performReturn (emitKnownConReturnCode data_con) }
+ ; performReturn emitReturnInstr }
-- noStmts: Ptr to thing already in Node
; whenC (not (isNullaryRepDataCon data_con))
-- Dynamic-Closure first, to reduce forward references
; emit_info static_cl_info tickyEnterStaticCon }
-
- where
\end{code}