pass arguments to unknown function calls in registers
[ghc-hetmet.git] / ghc / compiler / codeGen / CgHeapery.lhs
index 8227689..184af90 100644 (file)
@@ -1,7 +1,7 @@
 %
 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
-% $Id: CgHeapery.lhs,v 1.45 2005/03/31 10:16:34 simonmar Exp $
+% $Id: CgHeapery.lhs,v 1.47 2005/06/21 10:44:41 simonmar Exp $
 %
 \section[CgHeapery]{Heap management functions}
 
@@ -23,7 +23,6 @@ module CgHeapery (
 
 #include "HsVersions.h"
 
-import Constants       ( mIN_UPD_SIZE )
 import StgSyn          ( AltType(..) )
 import CLabel          ( CLabel, mkRtsCodeLabel )
 import CgUtils         ( mkWordCLit, cmmRegOffW, cmmOffsetW,
@@ -40,7 +39,8 @@ import ClosureInfo    ( closureSize, staticClosureNeedsLink,
                          nodeMustPointToIt, closureLFInfo,                     
                          ClosureInfo )
 import SMRep           ( CgRep(..), cgRepSizeW, separateByPtrFollowness,
-                         WordOff, fixedHdrSize, isVoidArg, primRepToCgRep )
+                         WordOff, fixedHdrSize, thunkHdrSize,
+                         isVoidArg, primRepToCgRep )
 
 import Cmm             ( CmmLit(..), CmmStmt(..), CmmExpr(..), GlobalReg(..),
                          CmmReg(..), hpReg, nodeReg, spReg )
@@ -53,11 +53,9 @@ import TyCon         ( tyConPrimRep )
 import CostCentre      ( CostCentreStack )
 import Util            ( mapAccumL, filterOut )
 import Constants       ( wORD_SIZE )
-import DynFlags        ( DynFlags )
+import Packages                ( HomeModules )
 import Outputable
 
-import GLAEXTS
-
 \end{code}
 
 
@@ -125,7 +123,7 @@ getHpRelOffset virtual_offset
 
 \begin{code}
 layOutDynConstr, layOutStaticConstr
-       :: DynFlags
+       :: HomeModules
        -> DataCon      
        -> [(CgRep,a)]
        -> (ClosureInfo,
@@ -134,13 +132,13 @@ layOutDynConstr, layOutStaticConstr
 layOutDynConstr    = layOutConstr False
 layOutStaticConstr = layOutConstr True
 
-layOutConstr  is_static dflags data_con args
-   = (mkConInfo dflags is_static data_con tot_wds ptr_wds,
+layOutConstr  is_static hmods data_con args
+   = (mkConInfo hmods is_static data_con tot_wds ptr_wds,
       things_w_offsets)
   where
     (tot_wds,           --  #ptr_wds + #nonptr_wds
      ptr_wds,           --  #ptr_wds
-     things_w_offsets) = mkVirtHeapOffsets args
+     things_w_offsets) = mkVirtHeapOffsets False{-not a thunk-} args
 \end{code}
 
 @mkVirtHeapOffsets@ always returns boxed things with smaller offsets
@@ -149,7 +147,8 @@ list
 
 \begin{code}
 mkVirtHeapOffsets
-         :: [(CgRep,a)]        -- Things to make offsets for
+         :: Bool               -- True <=> is a thunk
+         -> [(CgRep,a)]        -- Things to make offsets for
          -> (WordOff,          -- _Total_ number of words allocated
              WordOff,          -- Number of words allocated for *pointers*
              [(a, VirtualHpOffset)])
@@ -158,7 +157,7 @@ mkVirtHeapOffsets
 
 -- First in list gets lowest offset, which is initial offset + 1.
 
-mkVirtHeapOffsets things
+mkVirtHeapOffsets is_thunk things
   = let non_void_things                      = filterOut (isVoidArg . fst) things
        (ptrs, non_ptrs)              = separateByPtrFollowness non_void_things
        (wds_of_ptrs, ptrs_w_offsets) = mapAccumL computeOffset 0 ptrs
@@ -166,8 +165,11 @@ mkVirtHeapOffsets things
     in
     (tot_wds, wds_of_ptrs, ptrs_w_offsets ++ non_ptrs_w_offsets)
   where
+    hdr_size   | is_thunk   = thunkHdrSize
+               | otherwise  = fixedHdrSize
+
     computeOffset wds_so_far (rep, thing)
-      = (wds_so_far + cgRepSizeW rep, (thing, fixedHdrSize + wds_so_far))
+      = (wds_so_far + cgRepSizeW rep, (thing, hdr_size + wds_so_far))
 \end{code}
 
 
@@ -209,8 +211,7 @@ mkStaticClosureFields cl_info ccs caf_refs payload
 
     padding_wds
        | not is_caf = []
-       | otherwise  = replicate n (mkIntCLit 0) -- a bunch of 0s
-       where n = max 0 (mIN_UPD_SIZE - length payload)
+       | otherwise  = ASSERT(null payload) [mkIntCLit 0]
 
     static_link_field
        | is_caf || staticClosureNeedsLink cl_info = [static_link_value]
@@ -227,6 +228,7 @@ mkStaticClosureFields cl_info ccs caf_refs payload
        | caf_refs      = mkIntCLit 0
        | otherwise     = mkIntCLit 1
 
+
 mkStaticClosure :: CLabel -> CostCentreStack -> [CmmLit]
   -> [CmmLit] -> [CmmLit] -> [CmmLit] -> [CmmLit]
 mkStaticClosure info_lbl ccs payload padding_wds static_link_field saved_info_field