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
47 table | infoTblNeedsSRT cl_info = srt_label : rest_of_table
48 | otherwise = rest_of_table
52 {- par, prof, debug -}
53 StInt (toInteger layout_info)
54 , StInt (toInteger type_info)
57 -- sigh: building up the info table is endian-dependent.
58 -- ToDo: do this using .byte and .word directives.
60 #ifdef WORDS_BIGENDIAN
61 type_info = (fromInt flags `shiftL` 24) .|.
62 (fromInt closure_type `shiftL` 16) .|.
65 type_info = (fromInt flags) .|.
66 (fromInt closure_type `shiftL` 8) .|.
67 (fromInt srt_len `shiftL` 16)
69 srt = getSRTInfo cl_info
73 (lbl, NoSRT) -> (StInt 0, 0)
75 (StIndex DataPtrRep (StCLbl lbl)
76 (StInt (toInteger off)), len)
79 #ifdef WORDS_BIGENDIAN
80 layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
82 layout_info = (fromInt ptrs) .|. (fromInt nptrs `shiftL` 16)
85 ptrs = closurePtrsSize cl_info
88 size = closureNonHdrSize cl_info
90 closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
99 -> Bool -- must include SRT field (i.e. it's a vector)
100 -> UniqSM StixTreeList
102 genBitmapInfoTable liveness srt closure_type include_srt
103 = returnUs (\xs -> StData PtrRep table : xs)
106 table = if srt_len == 0 && not include_srt then
109 srt_label : rest_of_table
113 {- par, prof, debug -}
115 , StInt (toInteger type_info)
118 layout_info = case liveness of
119 LvSmall mask -> StInt (toInteger (intBS mask))
120 LvLarge lbl -> StCLbl lbl
123 #ifdef WORDS_BIGENDIAN
124 type_info = (fromInt flags `shiftL` 24) .|.
125 (fromInt closure_type `shiftL` 16) .|.
128 type_info = (fromInt flags) .|.
129 (fromInt closure_type `shiftL` 8) .|.
130 (fromInt srt_len `shiftL` 16)
133 (srt_label,srt_len) =
135 (lbl, NoSRT) -> (StInt 0, 0)
136 (lbl, SRT off len) ->
137 (StIndex DataPtrRep (StCLbl lbl)
138 (StInt (toInteger off)), len)