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 StgSyn ( SRT(..) )
20 import ClosureInfo ( closurePtrsSize,
21 closureNonHdrSize, closureSMRep,
23 closureSRT, closureSemiTag
25 import PrimRep ( PrimRep(..) )
26 import SMRep ( getSMRepClosureTypeInt )
27 import Stix -- all of it
28 import UniqSupply ( returnUs, UniqSM )
29 import BitSet ( BitSet, intBS )
30 import Maybes ( maybeToBool )
36 Generating code for info tables (arrays of data).
41 -> UniqSM StixStmtList
43 genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
44 = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs)
47 info_lbl = infoTableLabelFromCI cl_info
49 table | needs_srt = srt_label : rest_of_table
50 | otherwise = rest_of_table
54 {- par, prof, debug -}
55 StInt (toInteger layout_info)
56 , StInt (toInteger type_info)
59 -- sigh: building up the info table is endian-dependent.
60 -- ToDo: do this using .byte and .word directives.
62 #ifdef WORDS_BIGENDIAN
63 type_info = (fromIntegral closure_type `shiftL` 16) .|.
64 (fromIntegral srt_len)
66 type_info = (fromIntegral closure_type) .|.
67 (fromIntegral srt_len `shiftL` 16)
69 srt = closureSRT cl_info
70 needs_srt = needsSRT srt
77 NoC_SRT -> (StInt 0, 0)
78 C_SRT lbl off len -> (StIndex DataPtrRep (StCLbl lbl) (StInt (toInteger off)), len)
80 maybe_tag = closureSemiTag cl_info
81 is_constr = maybeToBool maybe_tag
82 (Just tag) = maybe_tag
85 #ifdef WORDS_BIGENDIAN
86 layout_info = (fromIntegral ptrs `shiftL` 16) .|. fromIntegral nptrs
88 layout_info = (fromIntegral ptrs) .|. (fromIntegral nptrs `shiftL` 16)
91 ptrs = closurePtrsSize cl_info
94 size = closureNonHdrSize cl_info
96 closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
104 -> Bool -- must include SRT field (i.e. it's a vector)
105 -> UniqSM StixStmtList
107 genBitmapInfoTable liveness srt closure_type include_srt
108 = returnUs (\xs -> StData PtrRep table : xs)
111 table = if srt_len == 0 && not include_srt then
114 srt_label : rest_of_table
118 {- par, prof, debug -}
120 , StInt (toInteger type_info)
123 layout_info = case liveness of
125 case bitmapToIntegers mask of
131 #ifdef WORDS_BIGENDIAN
132 type_info = (fromIntegral closure_type `shiftL` 16) .|.
133 (fromIntegral srt_len)
135 type_info = (fromIntegral closure_type) .|.
136 (fromIntegral srt_len `shiftL` 16)
139 (srt_label,srt_len) =
141 NoC_SRT -> (StInt 0, 0)
143 (StIndex DataPtrRep (StCLbl lbl)
144 (StInt (toInteger off)), len)
146 bitmapToIntegers :: [BitSet] -> [Integer]
147 bitmapToIntegers = bundle . map (toInteger . intBS)
149 #if BYTES_PER_WORD == 4
153 bundle is = case splitAt (BYTES_PER_WORD/4) is of
155 ( foldr1 (\x y -> x + 4294967296 * y)
156 [x `mod` 4294967296 | x <- these]
161 bitmapIsSmall :: [BitSet] -> Bool
163 = case bitmapToIntegers bitmap of
167 livenessIsSmall :: Liveness -> Bool
168 livenessIsSmall (Liveness _ mask) = bitmapIsSmall mask