Wolfgang Jeltsch pushed to branch wip/jeltsch/portable-bco-byte-array-serialization at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • libraries/ghci/GHCi/ResolvedBCO.hs
    ... ... @@ -20,6 +20,8 @@ module GHCi.ResolvedBCO
    20 20
     #error Bytecode serialization works only on 32- and 64-bit platforms.
    
    21 21
     #endif
    
    22 22
     
    
    23
    +#define LITTLE_ENDIAN_64_BITS (!defined(WORDS_BIGENDIAN) && SIZEOF_HSWORD == 8)
    
    24
    +
    
    23 25
     import Prelude -- See note [Why do we import Prelude here?]
    
    24 26
     
    
    25 27
     import GHCi.RemoteTypes
    
    ... ... @@ -39,7 +41,7 @@ import Foreign.Storable (Storable, sizeOf)
    39 41
     import GHC.Data.SmallArray (SmallArray)
    
    40 42
     import GHC.Generics (Generic)
    
    41 43
     
    
    42
    -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
    
    44
    +#if !LITTLE_ENDIAN_64_BITS
    
    43 45
     import Control.Monad (replicateM)
    
    44 46
     #endif
    
    45 47
     
    
    ... ... @@ -98,7 +100,7 @@ data BCOByteArray a
    98 100
             getBCOByteArray :: !ByteArray#
    
    99 101
       }
    
    100 102
     
    
    101
    -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
    
    103
    +#if !LITTLE_ENDIAN_64_BITS
    
    102 104
     
    
    103 105
     fromBCOByteArray :: Storable a => BCOByteArray a -> UArray Int a
    
    104 106
     fromBCOByteArray @a (BCOByteArray ba#) = UArray 0 (n - 1) n ba#
    
    ... ... @@ -146,7 +148,7 @@ instance Binary ResolvedBCO where
    146 148
           1 -> ResolvedStaticCon <$> get <*> get <*> get <*> get <*> get <*> get
    
    147 149
           _ -> error "Binary ResolvedBCO: invalid byte"
    
    148 150
     
    
    149
    -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
    
    151
    +#if !LITTLE_ENDIAN_64_BITS
    
    150 152
     
    
    151 153
     -- | Serialize a 'BCOByteArray', not writing the payload verbatim but
    
    152 154
     --   serializing the individual elements. This can be used with any host
    
    ... ... @@ -223,12 +225,12 @@ instance Binary (BCOByteArray Word16) where
    223 225
     -- See Note [BCOByteArray serialization].
    
    224 226
     instance Binary (BCOByteArray Word) where
    
    225 227
     
    
    226
    -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
    
    227
    -  put = putBCOByteArrayPortably (putWord64le . fromIntegral)
    
    228
    -  get = getBCOByteArrayPortably (fromIntegral <$> getWord64le)
    
    229
    -#else
    
    228
    +#if LITTLE_ENDIAN_64_BITS
    
    230 229
       put = putBCOByteArrayDirectly
    
    231 230
       get = getBCOByteArrayDirectly
    
    231
    +#else
    
    232
    +  put = putBCOByteArrayPortably (putWord64le . fromIntegral)
    
    233
    +  get = getBCOByteArrayPortably (fromIntegral <$> getWord64le)
    
    232 234
     #endif
    
    233 235
     
    
    234 236
     -- Note [BCOByteArray serialization]