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
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 )
29 #if __GLASGOW_HASKELL__ >= 404
30 import GlaExts ( fromInt )
34 Generating code for info tables (arrays of data).
39 -> UniqSM StixTreeList
41 genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
42 = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs)
45 info_lbl = infoTableLabelFromCI cl_info
46 needs_srt = infoTblNeedsSRT cl_info
48 table | needs_srt = srt_label : rest_of_table
49 | otherwise = rest_of_table
53 {- par, prof, debug -}
54 StInt (toInteger layout_info)
55 , StInt (toInteger type_info)
58 -- sigh: building up the info table is endian-dependent.
59 -- ToDo: do this using .byte and .word directives.
61 #ifdef WORDS_BIGENDIAN
62 type_info = (fromInt flags `shiftL` 24) .|.
63 (fromInt closure_type `shiftL` 16) .|.
66 type_info = (fromInt flags) .|.
67 (fromInt closure_type `shiftL` 8) .|.
68 (fromInt srt_len `shiftL` 16)
70 srt = getSRTInfo cl_info
76 (StIndex DataPtrRep (StCLbl lbl)
77 (StInt (toInteger off)), len)
82 #ifdef WORDS_BIGENDIAN
83 layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
85 layout_info = (fromInt ptrs) .|. (fromInt nptrs `shiftL` 16)
88 ptrs = closurePtrsSize cl_info
91 size = closureNonHdrSize cl_info
93 closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
102 -> Bool -- must include SRT field (i.e. it's a vector)
103 -> UniqSM StixTreeList
105 genBitmapInfoTable liveness srt closure_type include_srt
106 = returnUs (\xs -> StData PtrRep table : xs)
109 table = if srt_len == 0 && not include_srt then
112 srt_label : rest_of_table
116 {- par, prof, debug -}
118 , StInt (toInteger type_info)
121 layout_info = case liveness of
122 LvSmall mask -> StInt (toInteger (intBS mask))
123 LvLarge lbl -> StCLbl lbl
126 #ifdef WORDS_BIGENDIAN
127 type_info = (fromInt flags `shiftL` 24) .|.
128 (fromInt closure_type `shiftL` 16) .|.
131 type_info = (fromInt flags) .|.
132 (fromInt closure_type `shiftL` 8) .|.
133 (fromInt srt_len `shiftL` 16)
136 (srt_label,srt_len) =
138 (lbl, NoSRT) -> (StInt 0, 0)
139 (lbl, SRT off len) ->
140 (StIndex DataPtrRep (StCLbl lbl)
141 (StInt (toInteger off)), len)