2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
4 \section[CgUpdate]{Manipulating update frames}
7 #include "HsVersions.h"
9 module CgUpdate ( pushUpdateFrame ) where
15 import CgCompInfo ( sTD_UF_SIZE, cON_UF_SIZE,
16 sCC_STD_UF_SIZE, sCC_CON_UF_SIZE,
17 spARelToInt, spBRelToInt
19 import CgStackery ( allocUpdateFrame )
21 import CmdLineOpts ( GlobalSwitch(..) )
26 %********************************************************
28 %* Setting up update frames *
30 %********************************************************
31 \subsection[setting-update-frames]{Setting up update frames}
33 @pushUpdateFrame@ $updatee$ pushes a general update frame which
34 points to $updatee$ as the thing to be updated. It is only used
35 when a thunk has just been entered, so the (real) stack pointers
36 are guaranteed to be nicely aligned with the top of stack.
37 @pushUpdateFrame@ adjusts the virtual and tail stack pointers
38 to reflect the frame pushed.
41 pushUpdateFrame :: CAddrMode -> CAddrMode -> Code -> Code
43 pushUpdateFrame updatee vector code
44 = isSwitchSetC SccProfilingOn `thenFC` \ profiling_on ->
46 -- frame_size *includes* the return address
47 frame_size = if profiling_on
51 getEndOfBlockInfo `thenFC` \ eob_info ->
52 ASSERT(case eob_info of { EndOfBlockInfo _ _ InRetReg -> True; _ -> False})
53 allocUpdateFrame frame_size vector (\ _ ->
55 -- Emit the push macro
56 absC (CMacroStmt PUSH_STD_UPD_FRAME [
58 int_CLit0, -- Known to be zero because we have just
59 int_CLit0 -- entered a thunk
64 int_CLit0 = mkIntCLit 0 -- out here to avoid pushUpdateFrame CAF (sigh)
66 {- ---------------------
67 What actually happens is something like this; but it got macro-ised
69 = pushOnBStack (CReg CurCostCentre) `thenFC` \ _ ->
70 pushOnBStack (CReg SuA) `thenFC` \ _ ->
71 pushOnBStack (CReg SuB) `thenFC` \ _ ->
72 pushOnBStack updatee `thenFC` \ _ ->
73 pushOnBStack (CLabel sTD_UPD_RET_VEC_LABEL CodePtrRep) `thenFC` \ _ ->
75 -- MAKE SuA, SuB POINT TO TOP OF A,B STACKS
76 -- Remember, SpB hasn't yet been incremented to account for the
77 -- 4-word update frame which has been pushed.
78 -- This code seems crude, but effective...
79 absC (AbsCStmts (CAssign (CReg SuA) (CReg SpA))
80 (CAssign (CReg SuB) (CAddr (SpBRel 0 4))))
81 -------------------------- -}