separateByPtrFollowness, isFollowableRep, isFloatingRep,
getPrimRepSize, retPrimRepSize,
- showPrimRep,
- guessPrimRep
+ showPrimRep, ppPrimRep,
+ guessPrimRep, decodePrimRep
) where
-import Ubiq
+IMP_Ubiq()
import Pretty -- pretty-printing code
import Util
+#if __GLASGOW_HASKELL__ >= 202
+import Outputable
+#endif
+-- Oh dear.
#include "../../includes/GhcConstants.h"
\end{code}
| FloatRep -- floats
| DoubleRep -- doubles
- | MallocPtrRep -- This has to be a special kind because ccall
+ | ForeignObjRep -- This has to be a special kind because ccall
-- generates special code when passing/returning
-- one of these. [ADR]
-- (Primitive states are mapped onto this)
deriving (Eq, Ord)
-- Kinds are used in PrimTyCons, which need both Eq and Ord
- -- Text is needed for derived-Text on PrimitiveOps
\end{code}
%************************************************************************
%************************************************************************
Whether or not the thing is a pointer that the garbage-collector
-should follow.
+should follow. Or, to put it another (less confusing) way, whether
+the object in question is a heap object.
-Or, to put it another (less confusing) way, whether the object in
-question is a heap object.
+Depending on the outcome, this predicate determines what stack
+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
isFollowableRep ByteArrayRep = True
-isFollowableRep MallocPtrRep = True
+-- why is a ForeignObj followable? 4/96 SOF
+--
+-- A: they're followable because these objects
+-- should be lugged around by the storage manager
+-- (==> registers containing them are live) -- 3/97 SOF
+isFollowableRep ForeignObjRep = True
isFollowableRep StablePtrRep = False
-- StablePtrs aren't followable because they are just indices into a
\begin{code}
instance Outputable PrimRep where
- ppr sty kind = ppStr (showPrimRep kind)
+ ppr sty kind = text (showPrimRep kind)
showPrimRep :: PrimRep -> String
+-- dumping PrimRep tag for unfoldings
+ppPrimRep :: PrimRep -> Doc
+
guessPrimRep :: String -> PrimRep -- a horrible "inverse" function
+decodePrimRep :: Char -> PrimRep -- of equal nature
+
+ppPrimRep k =
+ char
+ (case k of
+ PtrRep -> 'P'
+ CodePtrRep -> 'p'
+ DataPtrRep -> 'd'
+ CostCentreRep -> 'c' -- Pointer to a cost centre
+ RetRep -> 'R'
+ CharRep -> 'C'
+ IntRep -> 'I'
+ WordRep -> 'W'
+ AddrRep -> 'A'
+ FloatRep -> 'F'
+ DoubleRep -> 'D'
+ ArrayRep -> 'a'
+ ByteArrayRep -> 'b'
+ StablePtrRep -> 'S'
+ ForeignObjRep -> 'f'
+ VoidRep -> 'V'
+ _ -> panic "ppPrimRep")
showPrimRep PtrRep = "P_" -- short for StgPtr
showPrimRep ArrayRep = "StgArray" -- see comment below
showPrimRep ByteArrayRep = "StgByteArray"
showPrimRep StablePtrRep = "StgStablePtr"
-showPrimRep MallocPtrRep = "StgPtr" -- see comment below
+showPrimRep ForeignObjRep = "StgPtr" -- see comment below
showPrimRep VoidRep = "!!VOID_KIND!!"
+decodePrimRep ch =
+ case ch of
+ 'P' -> PtrRep
+ 'p' -> CodePtrRep
+ 'd' -> DataPtrRep
+ 'c' -> CostCentreRep
+ 'R' -> RetRep
+ 'C' -> CharRep
+ 'I' -> IntRep
+ 'W' -> WordRep
+ 'A' -> AddrRep
+ 'F' -> FloatRep
+ 'D' -> DoubleRep
+ 'a' -> ArrayRep
+ 'b' -> ByteArrayRep
+ 'S' -> StablePtrRep
+ 'f' -> ForeignObjRep
+ 'V' -> VoidRep
+ _ -> panic "decodePrimRep"
+
guessPrimRep "D_" = DataPtrRep
guessPrimRep "StgRetAddr" = RetRep
guessPrimRep "StgChar" = CharRep
@StgArray@. The coercion to a more precise C type is done just before
indexing (by the relevant C primitive-op macro).
-Nota Bene. There are three types associated with Malloc Pointers:
+Nota Bene. There are three types associated with @ForeignObj@ (MallocPtr++):
\begin{itemize}
\item
-@StgMallocClosure@ is the type of the thing the C world gives us.
+@StgForeignObjClosure@ is the type of the thing the prim. op @mkForeignObj@ returns.
+{- old comment for MallocPtr
(This typename is hardwired into @ppr_casm_results@ in
@PprAbsC.lhs@.)
+-}
\item
-@StgMallocPtr@ is the type of the thing we give the C world.
+@StgForeignObj@ is the type of the thing we give the C world.
\item
@StgPtr@ is the type of the (pointer to the) heap object which we