[Git][ghc/ghc][wip/jeltsch/portable-bco-byte-array-serialization] Introduce and use a macro `LITTLE_ENDIAN_64_BITS`
Wolfgang Jeltsch pushed to branch wip/jeltsch/portable-bco-byte-array-serialization at Glasgow Haskell Compiler / GHC Commits: 4a46820f by Wolfgang Jeltsch at 2026-11-26T17:20:30+02:00 Introduce and use a macro `LITTLE_ENDIAN_64_BITS` - - - - - 1 changed file: - libraries/ghci/GHCi/ResolvedBCO.hs Changes: ===================================== libraries/ghci/GHCi/ResolvedBCO.hs ===================================== @@ -20,6 +20,8 @@ module GHCi.ResolvedBCO #error Bytecode serialization works only on 32- and 64-bit platforms. #endif +#define LITTLE_ENDIAN_64_BITS (!defined(WORDS_BIGENDIAN) && SIZEOF_HSWORD == 8) + import Prelude -- See note [Why do we import Prelude here?] import GHCi.RemoteTypes @@ -39,7 +41,7 @@ import Foreign.Storable (Storable, sizeOf) import GHC.Data.SmallArray (SmallArray) import GHC.Generics (Generic) -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4 +#if !LITTLE_ENDIAN_64_BITS import Control.Monad (replicateM) #endif @@ -98,7 +100,7 @@ data BCOByteArray a getBCOByteArray :: !ByteArray# } -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4 +#if !LITTLE_ENDIAN_64_BITS fromBCOByteArray :: Storable a => BCOByteArray a -> UArray Int a fromBCOByteArray @a (BCOByteArray ba#) = UArray 0 (n - 1) n ba# @@ -146,7 +148,7 @@ instance Binary ResolvedBCO where 1 -> ResolvedStaticCon <$> get <*> get <*> get <*> get <*> get <*> get _ -> error "Binary ResolvedBCO: invalid byte" -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4 +#if !LITTLE_ENDIAN_64_BITS -- | Serialize a 'BCOByteArray', not writing the payload verbatim but -- serializing the individual elements. This can be used with any host @@ -223,12 +225,12 @@ instance Binary (BCOByteArray Word16) where -- See Note [BCOByteArray serialization]. instance Binary (BCOByteArray Word) where -#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4 - put = putBCOByteArrayPortably (putWord64le . fromIntegral) - get = getBCOByteArrayPortably (fromIntegral <$> getWord64le) -#else +#if LITTLE_ENDIAN_64_BITS put = putBCOByteArrayDirectly get = getBCOByteArrayDirectly +#else + put = putBCOByteArrayPortably (putWord64le . fromIntegral) + get = getBCOByteArrayPortably (fromIntegral <$> getWord64le) #endif -- Note [BCOByteArray serialization] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a46820fb7cea7a57869a071729b6058... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a46820fb7cea7a57869a071729b6058... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Wolfgang Jeltsch (@jeltsch)