From: sof Date: Wed, 30 Sep 1998 08:49:46 +0000 (+0000) Subject: [project @ 1998-09-30 08:49:45 by sof] X-Git-Tag: Approx_2487_patches~252 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=63badf5a0e2c5b0fa63c6d633097453789baf82f;p=ghc-hetmet.git [project @ 1998-09-30 08:49:45 by sof] Protect uses of ForeignObj with #ifndef __PARALLEL_HASKELL__ --- diff --git a/ghc/lib/exts/Int.lhs b/ghc/lib/exts/Int.lhs index f5be8ca..7ecd4c1 100644 --- a/ghc/lib/exts/Int.lhs +++ b/ghc/lib/exts/Int.lhs @@ -53,16 +53,18 @@ module Int , sizeofInt32 , sizeofInt64 -#ifndef __PARALLEL_HASKELL__ -- The "official" place to get these from is Foreign +#ifndef __PARALLEL_HASKELL__ , indexInt8OffForeignObj , indexInt16OffForeignObj , indexInt32OffForeignObj , indexInt64OffForeignObj + , readInt8OffForeignObj , readInt16OffForeignObj , readInt32OffForeignObj , readInt64OffForeignObj + , writeInt8OffForeignObj , writeInt16OffForeignObj , writeInt32OffForeignObj @@ -1017,16 +1019,17 @@ indexInt64OffAddr (A# a#) (I# i#) #endif #ifndef __PARALLEL_HASKELL__ + indexInt8OffForeignObj :: ForeignObj -> Int -> Int8 indexInt8OffForeignObj (ForeignObj fo#) (I# i#) = intToInt8 (I# (ord# (indexCharOffForeignObj# fo# i#))) indexInt16OffForeignObj :: ForeignObj -> Int -> Int16 indexInt16OffForeignObj fo i = -#ifdef WORDS_BIGENDIAN +# ifdef WORDS_BIGENDIAN intToInt16 ( int8ToInt l + (int8ToInt maxBound) * int8ToInt h) -#else +# else intToInt16 ( int8ToInt h + (int8ToInt maxBound) * int8ToInt l) -#endif +# endif where byte_idx = i * 2 l = indexInt8OffForeignObj fo byte_idx @@ -1037,19 +1040,19 @@ indexInt32OffForeignObj (ForeignObj fo#) i = intToInt32 (I# (indexIntOffForeignO where -- adjust index to be in Int units, not Int32 ones. (I# i'#) -#if WORD_SIZE_IN_BYTES==8 +# if WORD_SIZE_IN_BYTES==8 = i `div` 2 -#else +# else = i -#endif +# endif indexInt64OffForeignObj :: ForeignObj -> Int -> Int64 indexInt64OffForeignObj (ForeignObj fo#) (I# i#) -#if WORD_SIZE_IN_BYTES==8 +# if WORD_SIZE_IN_BYTES==8 = I64# (indexIntOffForeignObj# fo# i#) -#else +# else = I64# (indexInt64OffForeignObj# fo# i#) -#endif +# endif #endif /* __PARALLEL_HASKELL__ */ \end{code} @@ -1074,6 +1077,7 @@ readInt64OffAddr a i = _casm_ `` %r=(StgInt64)(((StgInt64*)%0)[(StgInt)%1]); '' #endif #ifndef __PARALLEL_HASKELL__ + readInt8OffForeignObj :: ForeignObj -> Int -> IO Int8 readInt8OffForeignObj fo i = _casm_ `` %r=(StgInt8)(((StgInt8*)%0)[(StgInt)%1]); '' fo i @@ -1084,11 +1088,12 @@ readInt32OffForeignObj :: ForeignObj -> Int -> IO Int32 readInt32OffForeignObj fo i = _casm_ `` %r=(StgInt32)(((StgInt32*)%0)[(StgInt)%1]); '' fo i readInt64OffForeignObj :: ForeignObj -> Int -> IO Int64 -#if WORD_SIZE_IN_BYTES==8 +# if WORD_SIZE_IN_BYTES==8 readInt64OffForeignObj fo i = _casm_ `` %r=(StgInt)(((StgInt*)%0)[(StgInt)%1]); '' fo i -#else +# else readInt64OffForeignObj fo i = _casm_ `` %r=(StgInt64)(((StgInt64*)%0)[(StgInt)%1]); '' fo i -#endif +# endif + #endif /* __PARALLEL_HASKELL__ */ \end{code} @@ -1110,6 +1115,7 @@ writeInt64OffAddr a i e = _casm_ `` (((StgInt64*)%0)[(StgInt)%1])=(StgInt64)%2; #endif #ifndef __PARALLEL_HASKELL__ + writeInt8OffForeignObj :: ForeignObj -> Int -> Int8 -> IO () writeInt8OffForeignObj fo i e = _casm_ `` (((StgInt8*)%0)[(StgInt)%1])=(StgInt8)%2; '' fo i e @@ -1120,11 +1126,13 @@ writeInt32OffForeignObj :: ForeignObj -> Int -> Int32 -> IO () writeInt32OffForeignObj fo i e = _casm_ `` (((StgInt32*)%0)[(StgInt)%1])=(StgInt32)%2; '' fo i e writeInt64OffForeignObj :: ForeignObj -> Int -> Int64 -> IO () -#if WORD_SIZE_IN_BYTES==8 +# if WORD_SIZE_IN_BYTES==8 writeInt64OffForeignObj fo i e = _casm_ `` (((StgInt*)%0)[(StgInt)%1])=(StgInt)%2; '' fo i e -#else +# else writeInt64OffForeignObj fo i e = _casm_ `` (((StgInt64*)%0)[(StgInt)%1])=(StgInt64)%2; '' fo i e -#endif +# endif + #endif /* __PARALLEL_HASKELL__ */ + \end{code} diff --git a/ghc/lib/exts/Word.lhs b/ghc/lib/exts/Word.lhs index f8a6df4..d98d89a 100644 --- a/ghc/lib/exts/Word.lhs +++ b/ghc/lib/exts/Word.lhs @@ -69,6 +69,7 @@ module Word , sizeofWord64 -- The "official" place to get these from is Foreign +#ifndef __PARALLEL_HASKELL__ , indexWord8OffForeignObj , indexWord16OffForeignObj , indexWord32OffForeignObj @@ -83,6 +84,7 @@ module Word , writeWord16OffForeignObj , writeWord32OffForeignObj , writeWord64OffForeignObj +#endif -- non-standard, GHC specific , wordToInt @@ -1069,9 +1071,6 @@ NOTE: the index is in units of the size of the type, *not* bytes. indexWord8OffAddr :: Addr -> Int -> Word8 indexWord8OffAddr (A# a#) (I# i#) = intToWord8 (I# (ord# (indexCharOffAddr# a# i#))) -indexWord8OffForeignObj :: ForeignObj -> Int -> Word8 -indexWord8OffForeignObj (ForeignObj fo#) (I# i#) = intToWord8 (I# (ord# (indexCharOffForeignObj# fo# i#))) - indexWord16OffAddr :: Addr -> Int -> Word16 indexWord16OffAddr a i = #ifdef WORDS_BIGENDIAN @@ -1084,6 +1083,30 @@ indexWord16OffAddr a i = l = indexWord8OffAddr a byte_idx h = indexWord8OffAddr a (byte_idx+1) +indexWord32OffAddr :: Addr -> Int -> Word32 +indexWord32OffAddr (A# a#) i = wordToWord32 (W# (indexWordOffAddr# a# i'#)) + where + -- adjust index to be in Word units, not Word32 ones. + (I# i'#) +#if WORD_SIZE_IN_BYTES==8 + = i `div` 2 +#else + = i +#endif + +indexWord64OffAddr :: Addr -> Int -> Word64 +indexWord64OffAddr (A# a#) (I# i#) +#if WORD_SIZE_IN_BYTES==8 + = W64# (indexWordOffAddr# a# i#) +#else + = W64# (indexWord64OffAddr# a# i#) +#endif + +#ifndef __PARALLEL_HASKELL__ + +indexWord8OffForeignObj :: ForeignObj -> Int -> Word8 +indexWord8OffForeignObj (ForeignObj fo#) (I# i#) = intToWord8 (I# (ord# (indexCharOffForeignObj# fo# i#))) + indexWord16OffForeignObj :: ForeignObj -> Int -> Word16 indexWord16OffForeignObj fo i = #ifdef WORDS_BIGENDIAN @@ -1096,17 +1119,6 @@ indexWord16OffForeignObj fo i = l = indexWord8OffForeignObj fo byte_idx h = indexWord8OffForeignObj fo (byte_idx+1) -indexWord32OffAddr :: Addr -> Int -> Word32 -indexWord32OffAddr (A# a#) i = wordToWord32 (W# (indexWordOffAddr# a# i'#)) - where - -- adjust index to be in Word units, not Word32 ones. - (I# i'#) -#if WORD_SIZE_IN_BYTES==8 - = i `div` 2 -#else - = i -#endif - indexWord32OffForeignObj :: ForeignObj -> Int -> Word32 indexWord32OffForeignObj (ForeignObj fo#) i = wordToWord32 (W# (indexWordOffForeignObj# fo# i'#)) where @@ -1118,14 +1130,6 @@ indexWord32OffForeignObj (ForeignObj fo#) i = wordToWord32 (W# (indexWordOffFore = i #endif -indexWord64OffAddr :: Addr -> Int -> Word64 -indexWord64OffAddr (A# a#) (I# i#) -#if WORD_SIZE_IN_BYTES==8 - = W64# (indexWordOffAddr# a# i#) -#else - = W64# (indexWord64OffAddr# a# i#) -#endif - indexWord64OffForeignObj :: ForeignObj -> Int -> Word64 indexWord64OffForeignObj (ForeignObj fo#) (I# i#) #if WORD_SIZE_IN_BYTES==8 @@ -1133,6 +1137,7 @@ indexWord64OffForeignObj (ForeignObj fo#) (I# i#) #else = W64# (indexWord64OffForeignObj# fo# i#) #endif +#endif \end{code} @@ -1142,21 +1147,12 @@ Read words out of mutable memory: readWord8OffAddr :: Addr -> Int -> IO Word8 readWord8OffAddr a i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' a i -readWord8OffForeignObj :: ForeignObj -> Int -> IO Word8 -readWord8OffForeignObj fo i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' fo i - readWord16OffAddr :: Addr -> Int -> IO Word16 readWord16OffAddr a i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' a i -readWord16OffForeignObj :: ForeignObj -> Int -> IO Word16 -readWord16OffForeignObj fo i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' fo i - readWord32OffAddr :: Addr -> Int -> IO Word32 readWord32OffAddr a i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' a i -readWord32OffForeignObj :: ForeignObj -> Int -> IO Word32 -readWord32OffForeignObj fo i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' fo i - readWord64OffAddr :: Addr -> Int -> IO Word64 #if WORD_SIZE_IN_BYTES==8 readWord64OffAddr a i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' a i @@ -1164,12 +1160,25 @@ readWord64OffAddr a i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' a readWord64OffAddr a i = _casm_ `` %r=(StgWord64)(((StgWord64*)%0)[(StgInt)%1]); '' a i #endif +#ifndef __PARALLEL_HASKELL__ +readWord8OffForeignObj :: ForeignObj -> Int -> IO Word8 +readWord8OffForeignObj fo i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' fo i + +readWord16OffForeignObj :: ForeignObj -> Int -> IO Word16 +readWord16OffForeignObj fo i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' fo i + +readWord32OffForeignObj :: ForeignObj -> Int -> IO Word32 +readWord32OffForeignObj fo i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' fo i + readWord64OffForeignObj :: ForeignObj -> Int -> IO Word64 #if WORD_SIZE_IN_BYTES==8 readWord64OffForeignObj fo i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' fo i #else readWord64OffForeignObj fo i = _casm_ `` %r=(StgWord64)(((StgWord64*)%0)[(StgInt)%1]); '' fo i #endif + +#endif + \end{code} Note: we provide primops for the writing via Addrs since that's used @@ -1204,6 +1213,8 @@ writeWord64OffAddr (A# a#) (I# i#) (W64# w#) = IO $ \ s# -> case (writeWord64OffAddr# a# i# w# s#) of s2# -> IOok s2# () #endif +#ifndef __PARALLEL_HASKELL__ + writeWord8OffForeignObj :: ForeignObj -> Int -> Word8 -> IO () writeWord8OffForeignObj fo i w = _casm_ `` (((StgWord16*)%0)[(StgInt)%1])=(StgWord16)%2; '' fo i w @@ -1228,5 +1239,6 @@ writeWord64OffForeignObj fo i e = _casm_ `` (((StgWord*)%0)[(StgInt)%1])=(StgWor writeWord64OffForeignObj fo i e = _casm_ `` (((StgWord64*)%0)[(StgInt)%1])=(StgWord64)%2; '' fo i e #endif +#endif \end{code}