X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fprelude%2FPrimRep.lhs;h=a58240bdc21440df2b5548d916e5b6a87367f418;hb=553e90d9a32ee1b1809430f260c401cc4169c6c7;hp=b90c5cd3ee827aa396d27b6e0aa679f6bc7b1338;hpb=6142c28fbfb64b800f6a3530b623597eee9bd9be;p=ghc-hetmet.git diff --git a/ghc/compiler/prelude/PrimRep.lhs b/ghc/compiler/prelude/PrimRep.lhs index b90c5cd..a58240b 100644 --- a/ghc/compiler/prelude/PrimRep.lhs +++ b/ghc/compiler/prelude/PrimRep.lhs @@ -8,20 +8,19 @@ At various places in the back end, we want to be to tag things with a types. \begin{code} -module PrimRep - ( - PrimRep(..) - , separateByPtrFollowness - , isFollowableRep - , isFloatingRep - , is64BitRep - , getPrimRepSize - , getPrimRepSizeInBytes - , retPrimRepSize - , showPrimRep - , primRepString - , showPrimRepToUser - ) where +module PrimRep ( + PrimRep(..), + separateByPtrFollowness, + isFollowableRep, + isFloatingRep, + isNonPtrRep, + is64BitRep, + getPrimRepSize, + getPrimRepSizeInBytes, + retPrimRepSize, + + ArgRep(..), primRepToArgRep, + ) where #include "HsVersions.h" @@ -35,6 +34,8 @@ import Outputable %* * %************************************************************************ +These pretty much correspond to the C types declared in StgTypes.h. + \begin{code} data PrimRep = -- These pointer-kinds are all really the same, but we keep @@ -46,67 +47,28 @@ data PrimRep | CostCentreRep -- Pointer to a cost centre | CharRep -- Machine characters - | IntRep -- integers (same size as ptr on this arch) - | WordRep -- ditto (but *unsigned*) - | AddrRep -- addresses ("C pointers") + | IntRep -- signed integers (same size as ptr on this arch) + | WordRep -- unsigned integers (same size as ptr on this arch) + | AddrRep -- addresses (C pointers) | FloatRep -- floats | DoubleRep -- doubles - | Word64Rep -- guaranteed to be 64 bits (no more, no less.) - | Int64Rep -- guaranteed to be 64 bits (no more, no less.) - - -- These are not expected to appear in the front end. They are - -- only here to help the native code generator, and should appear - -- nowhere else. - | Int8Rep -- 8 bit signed integers - | Word8Rep -- 8 bit unsigned integers + + | Int8Rep -- 8 bit signed integers | Int16Rep -- 16 bit signed integers - | Word16Rep -- 16 bit unsigned integers | Int32Rep -- 32 bit signed integers + | Int64Rep -- 64 bit signed integers + | Word8Rep -- 8 bit unsigned integers + | Word16Rep -- 16 bit unsigned integers | Word32Rep -- 32 bit unsigned integers - - -- Perhaps all sized integers and words should be primitive types. - - -- Word8Rep is currently used to simulate some old CharRep usages - -- when Char changed size from 8 to 31 bits. It does not correspond - -- to a Haskell unboxed type, in particular it's not used by Word8. - - | WeakPtrRep - | ForeignObjRep - | BCORep + | Word64Rep -- 64 bit unsigned integers | StablePtrRep -- guaranteed to be represented by a pointer - | StableNameRep -- A stable name is a real heap object, unpointed, - -- with one field containing an index into the - -- stable pointer table. It has to be a heap - -- object so the garbage collector can track these - -- objects and reclaim stable pointer entries. - - | ThreadIdRep -- Really a pointer to a TSO - - | ArrayRep -- Primitive array of Haskell pointers - | ByteArrayRep -- Primitive array of bytes (no Haskell pointers) - - | PrimPtrRep -- Used for MutVars and MVars; - -- a pointer to a primitive object - -- ToDo: subsumes WeakPtrRep, ThreadIdRep, - -- StableNameRep, ForeignObjRep, and BCORep ? - | VoidRep -- Occupies no space at all! -- (Primitive states are mapped onto this) deriving (Eq, Ord) - -- Kinds are used in PrimTyCons, which need both Eq and Ord \end{code} -These pretty much correspond to the C types declared in StgTypes.h, -with the following exceptions: - - - when an Array or ByteArray is passed to C, we again pass a pointer - to the contents. The actual type that is passed is StgPtr for - ArrayRep, and StgByteArray (probably a char *) for ByteArrayRep. - -These hacks are left until the final printing of the C, in -PprAbsC.lhs. %************************************************************************ %* * @@ -123,22 +85,11 @@ the pointer/object possibly will have to be saved onto, and the computation of GC liveness info. \begin{code} -isFollowableRep :: PrimRep -> Bool - -isFollowableRep PtrRep = True -isFollowableRep ArrayRep = True -- all heap objects: -isFollowableRep ByteArrayRep = True -- '' -isFollowableRep WeakPtrRep = True -- '' -isFollowableRep ForeignObjRep = True -- '' -isFollowableRep StableNameRep = True -- '' -isFollowableRep PrimPtrRep = True -- '' -isFollowableRep ThreadIdRep = True -- pointer to a TSO -isFollowableRep BCORep = True - +isFollowableRep :: PrimRep -> Bool -- True <=> points to a heap object +isFollowableRep PtrRep = True isFollowableRep other = False separateByPtrFollowness :: (a -> PrimRep) -> [a] -> ([a], [a]) - separateByPtrFollowness kind_fun things = sep_things kind_fun things [] [] -- accumulating params for follow-able and don't-follow things... @@ -157,64 +108,99 @@ See codeGen/CgCon:cgTopRhsCon. \begin{code} isFloatingRep :: PrimRep -> Bool - isFloatingRep DoubleRep = True isFloatingRep FloatRep = True -isFloatingRep other = False +isFloatingRep _ = False +\end{code} +Identify anything which is one word large and not a pointer. + +\begin{code} +isNonPtrRep :: PrimRep -> Bool +isNonPtrRep PtrRep = False +isNonPtrRep VoidRep = False +isNonPtrRep r = not (isFloatingRep r) && not (is64BitRep r) \end{code} \begin{code} is64BitRep :: PrimRep -> Bool - is64BitRep Int64Rep = True is64BitRep Word64Rep = True -is64BitRep other = False +is64BitRep _ = False -\end{code} +-- Size in words. - - -\begin{code} getPrimRepSize :: PrimRep -> Int +getPrimRepSize DoubleRep = dOUBLE_SIZE +getPrimRepSize Word64Rep = wORD64_SIZE +getPrimRepSize Int64Rep = iNT64_SIZE +getPrimRepSize VoidRep = 0 +getPrimRepSize _ = 1 -getPrimRepSize DoubleRep = dOUBLE_SIZE -- "words", of course -getPrimRepSize Word64Rep = wORD64_SIZE -getPrimRepSize Int64Rep = iNT64_SIZE -getPrimRepSize VoidRep = 0 -getPrimRepSize other = 1 - +retPrimRepSize :: Int retPrimRepSize = getPrimRepSize RetRep --- sizes in bytes. --- (used in some settings to figure out how many bytes --- we have to push onto the stack when calling external --- entry points (e.g., stdcalling on win32) +-- Sizes in bytes. (used in some settings to figure out how many +-- bytes we have to push onto the stack when calling external entry +-- points (e.g., stdcalling on win32) + +-- Note: the "size in bytes" is also the scaling factor used when we +-- have an array of these things. For example, a ByteArray# of +-- Int16Rep will use a scaling factor of 2 when accessing the +-- elements. + getPrimRepSizeInBytes :: PrimRep -> Int -getPrimRepSizeInBytes pr = - case pr of - Int8Rep -> 1 - Word8Rep -> 1 - Int16Rep -> 2 - Word16Rep -> 2 - Int32Rep -> 4 - Word32Rep -> 4 - - CharRep -> 4 - IntRep -> wORD_SIZE - AddrRep -> wORD_SIZE - FloatRep -> wORD_SIZE - DoubleRep -> dOUBLE_SIZE * wORD_SIZE - Word64Rep -> wORD64_SIZE * wORD_SIZE - Int64Rep -> iNT64_SIZE * wORD_SIZE - WeakPtrRep -> wORD_SIZE - ForeignObjRep -> wORD_SIZE - StablePtrRep -> wORD_SIZE - StableNameRep -> wORD_SIZE - ArrayRep -> wORD_SIZE - ByteArrayRep -> wORD_SIZE - _ -> panic "getPrimRepSize: ouch - this wasn't supposed to happen!" +getPrimRepSizeInBytes PtrRep = wORD_SIZE +getPrimRepSizeInBytes CodePtrRep = wORD_SIZE +getPrimRepSizeInBytes DataPtrRep = wORD_SIZE +getPrimRepSizeInBytes RetRep = wORD_SIZE +getPrimRepSizeInBytes CostCentreRep = wORD_SIZE +getPrimRepSizeInBytes CharRep = 4 +getPrimRepSizeInBytes IntRep = wORD_SIZE +getPrimRepSizeInBytes WordRep = wORD_SIZE +getPrimRepSizeInBytes AddrRep = wORD_SIZE +getPrimRepSizeInBytes FloatRep = wORD_SIZE +getPrimRepSizeInBytes DoubleRep = dOUBLE_SIZE * wORD_SIZE +getPrimRepSizeInBytes Int8Rep = 1 +getPrimRepSizeInBytes Int16Rep = 2 +getPrimRepSizeInBytes Int32Rep = 4 +getPrimRepSizeInBytes Int64Rep = 8 +getPrimRepSizeInBytes Word8Rep = 1 +getPrimRepSizeInBytes Word16Rep = 2 +getPrimRepSizeInBytes Word32Rep = 4 +getPrimRepSizeInBytes Word64Rep = 8 +getPrimRepSizeInBytes StablePtrRep = wORD_SIZE +getPrimRepSizeInBytes other = pprPanic "getPrimRepSizeInBytes" (ppr other) +\end{code} +%************************************************************************ +%* * +\subsection{ArgReps} +%* * +%************************************************************************ + +An ArgRep is similar to a PrimRep, except that it is slightly +narrower. It corresponds to the distinctions we make between +different type of function arguments for the purposes of a function's +calling convention. These reps are used to decide which of the RTS's +generic apply functions to call when applying an unknown function. + +All 64-bit PrimReps map to the same ArgRep, because they're passed in +the same register, but a PtrRep is still different from an IntRep +(RepP vs. RepN respectively) because the function's entry convention +has to take into account the pointer-hood of arguments for the +purposes of describing the stack on entry to the garbage collector. + +\begin{code} +data ArgRep = RepV | RepP | RepN | RepF | RepD | RepL + +primRepToArgRep VoidRep = RepV +primRepToArgRep FloatRep = RepF +primRepToArgRep DoubleRep = RepD +primRepToArgRep r + | isFollowableRep r = RepP + | is64BitRep r = RepL + | otherwise = ASSERT(getPrimRepSize r == 1) RepN \end{code} %************************************************************************ @@ -228,8 +214,6 @@ instance Outputable PrimRep where ppr kind = text (showPrimRep kind) showPrimRep :: PrimRep -> String -showPrimRepToUser :: PrimRep -> String - showPrimRep PtrRep = "P_" -- short for StgPtr showPrimRep CodePtrRep = "P_" -- DEATH to StgFunPtr! (94/02/22 WDP) showPrimRep DataPtrRep = "D_" @@ -249,35 +233,8 @@ showPrimRep Word64Rep = "LW_" -- short for StgLongWord showPrimRep AddrRep = "StgAddr" showPrimRep FloatRep = "StgFloat" showPrimRep DoubleRep = "StgDouble" -showPrimRep ArrayRep = "P_" -- see comment below -showPrimRep PrimPtrRep = "P_" -showPrimRep ByteArrayRep = "StgByteArray" showPrimRep StablePtrRep = "StgStablePtr" -showPrimRep StableNameRep = "P_" -showPrimRep ThreadIdRep = "StgTSO*" -showPrimRep WeakPtrRep = "P_" -showPrimRep ForeignObjRep = "StgAddr" showPrimRep VoidRep = "!!VOID_KIND!!" -showPrimRep BCORep = "P_" -- not sure -- JRS 000708 - -primRepString CharRep = "Char" -primRepString Int8Rep = "Char" -- To have names like newCharArray# -primRepString IntRep = "Int" -primRepString WordRep = "Word" -primRepString Int64Rep = "Int64" -primRepString Word64Rep = "Word64" -primRepString AddrRep = "Addr" -primRepString FloatRep = "Float" -primRepString DoubleRep = "Double" -primRepString WeakPtrRep = "Weak" -primRepString ForeignObjRep = "ForeignObj" -primRepString StablePtrRep = "StablePtr" -primRepString StableNameRep = "StableName" -primRepString other = pprPanic "primRepString" (ppr other) - -showPrimRepToUser pr = primRepString pr \end{code} -Foreign Objects and Arrays are treated specially by the code for -_ccall_s: we pass a pointer to the contents of the object, not the -object itself. +