%
-% (c) The AQUA Project, Glasgow University, 1993-1996
+% (c) The AQUA Project, Glasgow University, 1993-1998
%
\begin{code}
-#include "HsVersions.h"
-
-module StixInfo ( genCodeInfoTable ) where
-
-IMP_Ubiq(){-uitious-}
+module StixInfo ( genCodeInfoTable, genBitmapInfoTable ) where
-import AbsCSyn ( AbstractC(..), CAddrMode, ReturnInfo,
- RegRelative, MagicId, CStmtMacro
- )
-import ClosureInfo ( closurePtrsSize, closureSizeWithoutFixedHdr,
- closureNonHdrSize, closureSemiTag, maybeSelectorInfo,
- closureSMRep, closureLabelFromCI,
- infoTableLabelFromCI
+#include "HsVersions.h"
+#include "../includes/config.h"
+
+import AbsCSyn ( AbstractC(..), Liveness(..) )
+import CLabel ( CLabel )
+import StgSyn ( SRT(..) )
+import ClosureInfo ( closurePtrsSize,
+ closureNonHdrSize, closureSMRep,
+ infoTableLabelFromCI,
+ infoTblNeedsSRT, getSRTInfo, closureSemiTag
)
-import HeapOffs ( hpRelToInt )
-import Maybes ( maybeToBool )
import PrimRep ( PrimRep(..) )
-import SMRep ( SMRep(..), SMSpecRepKind(..), SMUpdateKind(..),
- isSpecRep
- )
+import SMRep ( getSMRepClosureTypeInt )
import Stix -- all of it
-import StixPrim ( amodeToStix )
-import UniqSupply ( returnUs, SYN_IE(UniqSM) )
-import Unpretty ( uppBesides, uppPStr, uppInt, uppChar )
+import UniqSupply ( returnUs, UniqSM )
+import BitSet ( intBS )
+import Maybes ( maybeToBool )
+
+import Bits
+import Word
+
+#if __GLASGOW_HASKELL__ >= 404
+import GlaExts ( fromInt )
+#endif
\end{code}
Generating code for info tables (arrays of data).
\begin{code}
-static___rtbl = sStLitLbl SLIT("Static___rtbl") -- out here to avoid CAF (sigh)
-const___rtbl = sStLitLbl SLIT("Const___rtbl")
-charlike___rtbl = sStLitLbl SLIT("CharLike___rtbl")
-intlike___rtbl = sStLitLbl SLIT("IntLike___rtbl")
-gen_N___rtbl = sStLitLbl SLIT("Gen_N___rtbl")
-gen_S___rtbl = sStLitLbl SLIT("Gen_S___rtbl")
-gen_U___rtbl = sStLitLbl SLIT("Gen_U___rtbl")
-tuple___rtbl = sStLitLbl SLIT("Tuple___rtbl")
-data___rtbl = sStLitLbl SLIT("Data___rtbl")
-dyn___rtbl = sStLitLbl SLIT("Dyn___rtbl")
-
genCodeInfoTable
:: AbstractC
-> UniqSM StixTreeList
-genCodeInfoTable (CClosureInfoAndCode cl_info _ _ upd cl_descr _)
- = returnUs (\xs -> info : lbl : xs)
+genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr)
+ = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs)
where
- info = StData PtrRep table
- lbl = StLabel info_lbl
-
- table = case sm_rep of
- StaticRep _ _ -> [
- StInt (toInteger ptrs),
- StInt (toInteger size),
- upd_code,
- static___rtbl,
- tag]
-
- SpecialisedRep ConstantRep _ _ _ -> [
- StCLbl closure_lbl,
- upd_code,
- const___rtbl,
- tag]
-
- SpecialisedRep CharLikeRep _ _ _ -> [
- upd_code,
- charlike___rtbl,
- tag]
-
- SpecialisedRep IntLikeRep _ _ _ -> [
- upd_code,
- intlike___rtbl,
- tag]
-
- SpecialisedRep _ _ _ updatable ->
- let rtbl = uppBesides (
- if is_selector then
- [uppPStr SLIT("Select__"),
- uppInt select_word,
- uppPStr SLIT("_rtbl")]
- else
- [uppPStr (case updatable of
- SMNormalForm -> SLIT("Spec_N_")
- SMSingleEntry -> SLIT("Spec_S_")
- SMUpdatable -> SLIT("Spec_U_")
- ),
- uppInt size,
- uppChar '_',
- uppInt ptrs,
- uppPStr SLIT("_rtbl")])
- in
- case updatable of
- SMNormalForm -> [upd_code, StLitLbl rtbl, tag]
- _ -> [StLitLbl rtbl, tag]
-
- GenericRep _ _ updatable ->
- let rtbl = case updatable of
- SMNormalForm -> gen_N___rtbl
- SMSingleEntry -> gen_S___rtbl
- SMUpdatable -> gen_U___rtbl
- in [
- StInt (toInteger ptrs),
- StInt (toInteger size),
- upd_code,
- rtbl,
- tag]
-
- BigTupleRep _ -> [
- tuple___rtbl,
- tag]
- DataRep _ -> [
- data___rtbl,
- tag]
- DynamicRep -> [
- dyn___rtbl,
- tag]
-
- PhantomRep -> [
- upd_code,
- info_unused, -- no rep table
- tag]
-
- info_lbl = infoTableLabelFromCI cl_info
- closure_lbl = closureLabelFromCI cl_info
-
- sm_rep = closureSMRep cl_info
- maybe_selector = maybeSelectorInfo cl_info
- is_selector = maybeToBool maybe_selector
- (Just (_, select_word)) = maybe_selector
-
- tag = StInt (toInteger (closureSemiTag cl_info))
-
- size = if isSpecRep sm_rep
- then closureNonHdrSize cl_info
- else hpRelToInt (closureSizeWithoutFixedHdr cl_info)
- ptrs = closurePtrsSize cl_info
-
- upd_code = amodeToStix upd
-
- info_unused = StInt (-1)
+ info_lbl = infoTableLabelFromCI cl_info
+ needs_srt = infoTblNeedsSRT cl_info
+
+ table | needs_srt = srt_label : rest_of_table
+ | otherwise = rest_of_table
+
+ rest_of_table =
+ [
+ {- par, prof, debug -}
+ StInt (toInteger layout_info)
+ , StInt (toInteger type_info)
+ ]
+
+ -- sigh: building up the info table is endian-dependent.
+ -- ToDo: do this using .byte and .word directives.
+ type_info :: Word32
+#ifdef WORDS_BIGENDIAN
+ type_info = (fromInt closure_type `shiftL` 16) .|.
+ (fromInt srt_len)
+#else
+ type_info = (fromInt closure_type) .|.
+ (fromInt srt_len `shiftL` 16)
+#endif
+ srt = getSRTInfo cl_info
+
+ (srt_label,srt_len)
+ | is_constr
+ = (StInt 0, tag)
+ | needs_srt
+ = case srt of
+ (lbl, SRT off len) ->
+ (StIndex DataPtrRep (StCLbl lbl)
+ (StInt (toInteger off)), len)
+ | otherwise
+ = (StInt 0, 0)
+
+ maybe_tag = closureSemiTag cl_info
+ is_constr = maybeToBool maybe_tag
+ (Just tag) = maybe_tag
+
+ layout_info :: Word32
+#ifdef WORDS_BIGENDIAN
+ layout_info = (fromInt ptrs `shiftL` 16) .|. fromInt nptrs
+#else
+ layout_info = (fromInt ptrs) .|. (fromInt nptrs `shiftL` 16)
+#endif
+
+ ptrs = closurePtrsSize cl_info
+ nptrs = size - ptrs
+
+ size = closureNonHdrSize cl_info
+
+ closure_type = getSMRepClosureTypeInt (closureSMRep cl_info)
+
+
+
+genBitmapInfoTable
+ :: Liveness
+ -> (CLabel, SRT)
+ -> Int
+ -> Bool -- must include SRT field (i.e. it's a vector)
+ -> UniqSM StixTreeList
+
+genBitmapInfoTable liveness srt closure_type include_srt
+ = returnUs (\xs -> StData PtrRep table : xs)
+
+ where
+ table = if srt_len == 0 && not include_srt then
+ rest_of_table
+ else
+ srt_label : rest_of_table
+
+ rest_of_table =
+ [
+ {- par, prof, debug -}
+ layout_info
+ , StInt (toInteger type_info)
+ ]
+
+ layout_info = case liveness of
+ LvSmall mask -> StInt (toInteger (intBS mask))
+ LvLarge lbl -> StCLbl lbl
+
+ type_info :: Word32
+#ifdef WORDS_BIGENDIAN
+ type_info = (fromInt closure_type `shiftL` 16) .|.
+ (fromInt srt_len)
+#else
+ type_info = (fromInt closure_type) .|.
+ (fromInt srt_len `shiftL` 16)
+#endif
+
+ (srt_label,srt_len) =
+ case srt of
+ (lbl, NoSRT) -> (StInt 0, 0)
+ (lbl, SRT off len) ->
+ (StIndex DataPtrRep (StCLbl lbl)
+ (StInt (toInteger off)), len)
\end{code}