[project @ 2001-08-23 15:05:52 by simonpj]
[ghc-hetmet.git] / ghc / compiler / nativeGen / StixInfo.lhs
index 61bd8ec..fa1c07d 100644 (file)
@@ -3,10 +3,17 @@
 %
 
 \begin{code}
-module StixInfo ( genCodeInfoTable, genBitmapInfoTable ) where
+module StixInfo (
+
+       genCodeInfoTable, genBitmapInfoTable,
+
+       bitmapToIntegers, bitmapIsSmall, livenessIsSmall
+
+    ) where
 
 #include "HsVersions.h"
 #include "../includes/config.h"
+#include "NCG.h"
 
 import AbsCSyn         ( AbstractC(..), Liveness(..) )
 import CLabel          ( CLabel )
@@ -14,14 +21,14 @@ import StgSyn               ( SRT(..) )
 import ClosureInfo     ( closurePtrsSize,
                          closureNonHdrSize, closureSMRep,
                          infoTableLabelFromCI,
-                         infoTblNeedsSRT, getSRTInfo
+                         infoTblNeedsSRT, getSRTInfo, closureSemiTag
                        )
 import PrimRep         ( PrimRep(..) )
-import SMRep           ( SMRep(..), getSMRepClosureTypeInt )
+import SMRep           ( getSMRepClosureTypeInt )
 import Stix            -- all of it
 import UniqSupply      ( returnUs, UniqSM )
-import Outputable      ( int )
-import BitSet          ( intBS )
+import BitSet          ( BitSet, intBS )
+import Maybes          ( maybeToBool )
 
 import Bits
 import Word
@@ -68,6 +75,8 @@ genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
        srt = getSRTInfo cl_info             
 
        (srt_label,srt_len)
+           | is_constr
+           = (StInt 0, tag)
            | needs_srt
           = case srt of
                (lbl, SRT off len) -> 
@@ -76,6 +85,10 @@ genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
            | otherwise
            = (StInt 0, 0)
 
+        maybe_tag = closureSemiTag cl_info
+        is_constr = maybeToBool maybe_tag
+        (Just tag) = maybe_tag
+
        layout_info :: Word32
 #ifdef WORDS_BIGENDIAN
        layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
@@ -116,8 +129,11 @@ genBitmapInfoTable liveness srt closure_type include_srt
                ]
 
        layout_info = case liveness of
-                       LvSmall mask -> StInt (toInteger (intBS mask))
-                       LvLarge lbl  -> StCLbl lbl
+                     Liveness lbl mask ->
+                       case bitmapToIntegers mask of
+                       [ ] -> StInt 0
+                       [i] -> StInt i
+                       _   -> StCLbl lbl
 
        type_info :: Word32
 #ifdef WORDS_BIGENDIAN
@@ -134,4 +150,28 @@ genBitmapInfoTable liveness srt closure_type include_srt
                (lbl, SRT off len) -> 
                        (StIndex DataPtrRep (StCLbl lbl) 
                                (StInt (toInteger off)), len)
+
+bitmapToIntegers :: [BitSet] -> [Integer]
+bitmapToIntegers = bundle . map (toInteger . intBS)
+  where
+#if BYTES_PER_WORD == 4
+    bundle = id
+#else
+    bundle [] = []
+    bundle is = case splitAt (BYTES_PER_WORD/4) is of
+                (these, those) ->
+                   ( foldr1 (\x y -> x + 4294967296 * y)
+                            [x `mod` 4294967296 | x <- these]
+                   : bundle those
+                   )
+#endif
+
+bitmapIsSmall :: [BitSet] -> Bool
+bitmapIsSmall bitmap
+  = case bitmapToIntegers bitmap of
+    _:_:_ -> False
+    _     -> True
+
+livenessIsSmall :: Liveness -> Bool
+livenessIsSmall (Liveness _ mask) = bitmapIsSmall mask
 \end{code}