[project @ 2004-08-13 10:45:16 by simonmar]
[ghc-hetmet.git] / ghc / compiler / codeGen / CgUpdate.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
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 CgStackery       ( allocStackTop, updateFrameSize, setStackFrame )
15 import CgUsages         ( getVirtSp )
16 import Panic            ( assertPanic )
17 \end{code}
18
19
20 %********************************************************
21 %*                                                      *
22 %*              Setting up update frames                *
23 %*                                                      *
24 %********************************************************
25 \subsection[setting-update-frames]{Setting up update frames}
26
27 @pushUpdateFrame@ $updatee$ pushes a general update frame which
28 points to $updatee$ as the thing to be updated.  It is only used
29 when a thunk has just been entered, so the (real) stack pointers
30 are guaranteed to be nicely aligned with the top of stack.
31 @pushUpdateFrame@ adjusts the virtual and tail stack pointers
32 to reflect the frame pushed.
33
34 \begin{code}
35 pushUpdateFrame :: CAddrMode -> Code -> Code
36
37 pushUpdateFrame updatee code
38   = 
39 #ifdef DEBUG
40     getEndOfBlockInfo                   `thenFC` \ eob_info ->
41     ASSERT(case eob_info of { EndOfBlockInfo _ (OnStack _) -> True; 
42                               _ -> False})
43 #endif
44
45     allocStackTop updateFrameSize       `thenFC` \ _ ->
46     getVirtSp                           `thenFC` \ vsp ->
47
48     setStackFrame vsp                   `thenC`
49
50     setEndOfBlockInfo (EndOfBlockInfo vsp UpdateCode) (
51
52                 -- Emit the push macro
53             absC (CMacroStmt PUSH_UPD_FRAME [
54                         updatee,
55                         int_CLit0  -- we just entered a closure, so must be zero
56             ])
57             `thenC` code
58     )
59
60 int_CLit0 = mkIntCLit 0 -- out here to avoid pushUpdateFrame CAF (sigh)
61 \end{code}