2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[CgUpdate]{Manipulating update frames}
7 module CgUpdate ( pushUpdateFrame, reserveSeqFrame, pushSeqFrame ) where
9 #include "HsVersions.h"
14 import CgStackery ( allocStackTop, updateFrameSize, seqFrameSize )
15 import CgUsages ( getVirtSp, getSpRelOffset )
16 import Panic ( assertPanic )
20 %********************************************************
22 %* Setting up update frames *
24 %********************************************************
25 \subsection[setting-update-frames]{Setting up update frames}
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.
35 pushUpdateFrame :: CAddrMode -> Code -> Code
37 pushUpdateFrame updatee code
40 getEndOfBlockInfo `thenFC` \ eob_info ->
41 ASSERT(case eob_info of { EndOfBlockInfo _ (OnStack _) -> True;
45 allocStackTop updateFrameSize `thenFC` \ _ ->
46 getVirtSp `thenFC` \ vsp ->
48 setEndOfBlockInfo (EndOfBlockInfo vsp UpdateCode) (
50 -- Emit the push macro
51 absC (CMacroStmt PUSH_UPD_FRAME [
53 int_CLit0 -- we just entered a closure, so must be zero
58 int_CLit0 = mkIntCLit 0 -- out here to avoid pushUpdateFrame CAF (sigh)
61 We push a SEQ frame just before evaluating the scrutinee of a case, if
62 the scrutinee has a polymorphic or function type. The SEQ frame acts
63 as a barrier in case the scrutinee evaluates to a partial application.
65 reserveSeqFrame takes the EndOfBlockInfo for the case expression and
66 updates the sequel to a SeqFrame, reserving room for the frame at
67 args_sp. When the scrutinee comes around to pushing a return address,
68 it will also push the SEQ frame, using pushSeqFrame.
71 reserveSeqFrame :: EndOfBlockInfo -> EndOfBlockInfo
72 reserveSeqFrame (EndOfBlockInfo args_sp (CaseAlts amode stuff))
73 = EndOfBlockInfo (args_sp + seqFrameSize) (SeqFrame amode stuff)
75 pushSeqFrame :: VirtualSpOffset -> FCode VirtualSpOffset
77 = getSpRelOffset args_sp `thenFC` \ sp_rel ->
78 absC (CMacroStmt PUSH_SEQ_FRAME [CAddr sp_rel]) `thenC`
79 returnFC (args_sp - seqFrameSize)