43a21943d47b7d49bedd81cdf7c6d279f6b4904a
[ghc-hetmet.git] / ghc / compiler / codeGen / CgUpdate.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[CgUpdate]{Manipulating update frames}
5
6 \begin{code}
7 module CgUpdate ( pushUpdateFrame ) where
8
9 #include "HsVersions.h"
10
11 import CgMonad
12 import AbsCSyn
13
14 import Constants        ( sTD_UF_SIZE, sCC_STD_UF_SIZE )
15 import CgStackery       ( allocUpdateFrame )
16 import CmdLineOpts      ( opt_SccProfilingOn )
17 import Util             ( assertPanic )
18 \end{code}
19
20
21 %********************************************************
22 %*                                                      *
23 %*              Setting up update frames                *
24 %*                                                      *
25 %********************************************************
26 \subsection[setting-update-frames]{Setting up update frames}
27
28 @pushUpdateFrame@ $updatee$ pushes a general update frame which
29 points to $updatee$ as the thing to be updated.  It is only used
30 when a thunk has just been entered, so the (real) stack pointers
31 are guaranteed to be nicely aligned with the top of stack.
32 @pushUpdateFrame@ adjusts the virtual and tail stack pointers
33 to reflect the frame pushed.
34
35 \begin{code}
36 pushUpdateFrame :: CAddrMode -> CAddrMode -> Code -> Code
37
38 pushUpdateFrame updatee vector code
39   = let
40         profiling_on = opt_SccProfilingOn
41
42         -- frame_size *includes* the return address
43         frame_size = if profiling_on
44                      then sCC_STD_UF_SIZE
45                      else sTD_UF_SIZE
46     in
47     getEndOfBlockInfo                   `thenFC` \ eob_info ->
48     ASSERT(case eob_info of { EndOfBlockInfo _ _ InRetReg -> True; _ -> False})
49     allocUpdateFrame frame_size vector (\ _ ->
50
51                 -- Emit the push macro
52             absC (CMacroStmt PUSH_STD_UPD_FRAME [
53                         updatee,
54                         int_CLit0,      -- Known to be zero because we have just
55                         int_CLit0       -- entered a thunk
56             ])
57             `thenC` code
58     )
59
60 int_CLit0 = mkIntCLit 0 -- out here to avoid pushUpdateFrame CAF (sigh)
61
62 {- ---------------------
63     What actually happens is something like this; but it got macro-ised
64
65   = pushOnBStack (CReg CurCostCentre)                   `thenFC` \ _ ->
66     pushOnBStack (CReg SuA)                             `thenFC` \ _ ->
67     pushOnBStack (CReg SuB)                             `thenFC` \ _ ->
68     pushOnBStack updatee                                `thenFC` \ _ ->
69     pushOnBStack (CLabel sTD_UPD_RET_VEC_LABEL CodePtrRep) `thenFC` \ _ ->
70
71         -- MAKE SuA, SuB POINT TO TOP OF A,B STACKS
72         -- Remember, SpB hasn't yet been incremented to account for the
73         -- 4-word update frame which has been pushed.
74         -- This code seems crude, but effective...
75     absC (AbsCStmts (CAssign (CReg SuA) (CReg SpA))
76                     (CAssign (CReg SuB) (CAddr (SpBRel 0 4))))
77 -------------------------- -}
78 \end{code}