2 % (c) The AQUA Project, Glasgow University, 1993-1998
8 genCodeInfoTable, genBitmapInfoTable,
10 bitmapToIntegers, bitmapIsSmall, livenessIsSmall
14 #include "HsVersions.h"
15 #include "../includes/config.h"
18 import AbsCSyn ( AbstractC(..), Liveness(..), C_SRT(..), needsSRT )
19 import CLabel ( CLabel )
20 import StgSyn ( SRT(..) )
21 import ClosureInfo ( closurePtrsSize,
22 closureNonHdrSize, closureSMRep,
24 closureSRT, closureSemiTag
26 import PrimRep ( PrimRep(..) )
27 import SMRep ( getSMRepClosureTypeInt )
28 import Stix -- all of it
29 import UniqSupply ( returnUs, UniqSM )
30 import BitSet ( BitSet, intBS )
31 import Maybes ( maybeToBool )
36 #if __GLASGOW_HASKELL__ >= 404
37 import GlaExts ( fromInt )
41 Generating code for info tables (arrays of data).
46 -> UniqSM StixTreeList
48 genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
49 = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs)
52 info_lbl = infoTableLabelFromCI cl_info
54 table | needs_srt = srt_label : rest_of_table
55 | otherwise = rest_of_table
59 {- par, prof, debug -}
60 StInt (toInteger layout_info)
61 , StInt (toInteger type_info)
64 -- sigh: building up the info table is endian-dependent.
65 -- ToDo: do this using .byte and .word directives.
67 #ifdef WORDS_BIGENDIAN
68 type_info = (fromInt closure_type `shiftL` 16) .|.
71 type_info = (fromInt closure_type) .|.
72 (fromInt srt_len `shiftL` 16)
74 srt = closureSRT cl_info
75 needs_srt = needsSRT srt
82 NoC_SRT -> (StInt 0, 0)
83 C_SRT lbl off len -> (StIndex DataPtrRep (StCLbl lbl) (StInt (toInteger off)), len)
85 maybe_tag = closureSemiTag cl_info
86 is_constr = maybeToBool maybe_tag
87 (Just tag) = maybe_tag
90 #ifdef WORDS_BIGENDIAN
91 layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
93 layout_info = (fromInt ptrs) .|. (fromInt nptrs `shiftL` 16)
96 ptrs = closurePtrsSize cl_info
99 size = closureNonHdrSize cl_info
101 closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
109 -> Bool -- must include SRT field (i.e. it's a vector)
110 -> UniqSM StixTreeList
112 genBitmapInfoTable liveness srt closure_type include_srt
113 = returnUs (\xs -> StData PtrRep table : xs)
116 table = if srt_len == 0 && not include_srt then
119 srt_label : rest_of_table
123 {- par, prof, debug -}
125 , StInt (toInteger type_info)
128 layout_info = case liveness of
130 case bitmapToIntegers mask of
136 #ifdef WORDS_BIGENDIAN
137 type_info = (fromInt closure_type `shiftL` 16) .|.
140 type_info = (fromInt closure_type) .|.
141 (fromInt srt_len `shiftL` 16)
144 (srt_label,srt_len) =
146 NoC_SRT -> (StInt 0, 0)
148 (StIndex DataPtrRep (StCLbl lbl)
149 (StInt (toInteger off)), len)
151 bitmapToIntegers :: [BitSet] -> [Integer]
152 bitmapToIntegers = bundle . map (toInteger . intBS)
154 #if BYTES_PER_WORD == 4
158 bundle is = case splitAt (BYTES_PER_WORD/4) is of
160 ( foldr1 (\x y -> x + 4294967296 * y)
161 [x `mod` 4294967296 | x <- these]
166 bitmapIsSmall :: [BitSet] -> Bool
168 = case bitmapToIntegers bitmap of
172 livenessIsSmall :: Liveness -> Bool
173 livenessIsSmall (Liveness _ mask) = bitmapIsSmall mask