2 % (c) The AQUA Project, Glasgow University, 1993-1998
6 module StixInfo ( genCodeInfoTable, genBitmapInfoTable ) where
8 #include "HsVersions.h"
9 #include "../includes/config.h"
11 import AbsCSyn ( AbstractC(..), Liveness(..) )
12 import CLabel ( CLabel )
13 import StgSyn ( SRT(..) )
14 import ClosureInfo ( closurePtrsSize,
15 closureNonHdrSize, closureSMRep,
17 infoTblNeedsSRT, getSRTInfo, closureSemiTag
19 import PrimRep ( PrimRep(..) )
20 import SMRep ( SMRep(..), getSMRepClosureTypeInt )
21 import Stix -- all of it
22 import UniqSupply ( returnUs, UniqSM )
23 import Outputable ( int )
24 import BitSet ( intBS )
25 import Maybes ( maybeToBool )
30 #if __GLASGOW_HASKELL__ >= 404
31 import GlaExts ( fromInt )
35 Generating code for info tables (arrays of data).
40 -> UniqSM StixTreeList
42 genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
43 = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs)
46 info_lbl = infoTableLabelFromCI cl_info
47 needs_srt = infoTblNeedsSRT 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 = (fromInt closure_type `shiftL` 16) .|.
66 type_info = (fromInt closure_type) .|.
67 (fromInt srt_len `shiftL` 16)
69 srt = getSRTInfo cl_info
77 (StIndex DataPtrRep (StCLbl lbl)
78 (StInt (toInteger off)), len)
82 maybe_tag = closureSemiTag cl_info
83 is_constr = maybeToBool maybe_tag
84 (Just tag) = maybe_tag
87 #ifdef WORDS_BIGENDIAN
88 layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
90 layout_info = (fromInt ptrs) .|. (fromInt nptrs `shiftL` 16)
93 ptrs = closurePtrsSize cl_info
96 size = closureNonHdrSize cl_info
98 closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
106 -> Bool -- must include SRT field (i.e. it's a vector)
107 -> UniqSM StixTreeList
109 genBitmapInfoTable liveness srt closure_type include_srt
110 = returnUs (\xs -> StData PtrRep table : xs)
113 table = if srt_len == 0 && not include_srt then
116 srt_label : rest_of_table
120 {- par, prof, debug -}
122 , StInt (toInteger type_info)
125 layout_info = case liveness of
126 LvSmall mask -> StInt (toInteger (intBS mask))
127 LvLarge lbl -> StCLbl lbl
130 #ifdef WORDS_BIGENDIAN
131 type_info = (fromInt closure_type `shiftL` 16) .|.
134 type_info = (fromInt closure_type) .|.
135 (fromInt srt_len `shiftL` 16)
138 (srt_label,srt_len) =
140 (lbl, NoSRT) -> (StInt 0, 0)
141 (lbl, SRT off len) ->
142 (StIndex DataPtrRep (StCLbl lbl)
143 (StInt (toInteger off)), len)