summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-07-24 19:54:37 -0400
committerBen Gamari <ben@smart-cactus.org>2017-07-24 21:06:13 -0400
commit58545fde018460a2e9d05a8659951acfb277209f (patch)
treeda655fd49a5da068b39b370caa2a35c53788a2a8 /libraries
parent2183ac16a98146bb673b5530ca154499a1c6166e (diff)
downloadhaskell-58545fde018460a2e9d05a8659951acfb277209f.tar.gz
base: Introduce GHC.ByteOrder
This provides a ByteOrder type as well as a targetByteOrder value, which indicates the byte ordering used by the target machine. We might also consider exposing this via Data.Bits if the CLC is so inclined. Test Plan: Needs test Reviewers: hvr, RyanGlScott, austin Reviewed By: hvr, RyanGlScott Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3786
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/GHC/ByteOrder.hs31
-rw-r--r--libraries/base/base.cabal1
2 files changed, 32 insertions, 0 deletions
diff --git a/libraries/base/GHC/ByteOrder.hs b/libraries/base/GHC/ByteOrder.hs
new file mode 100644
index 0000000000..eecc56c9ad
--- /dev/null
+++ b/libraries/base/GHC/ByteOrder.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE CPP #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module : GHC.ByteOrder
+-- Copyright : (c) The University of Glasgow, 1994-2000
+-- License : see libraries/base/LICENSE
+--
+-- Maintainer : cvs-ghc@haskell.org
+-- Stability : internal
+-- Portability : non-portable (GHC extensions)
+--
+-- Target byte ordering.
+--
+-----------------------------------------------------------------------------
+
+module GHC.ByteOrder where
+
+-- | Byte ordering.
+data ByteOrder
+ = BigEndian -- ^ most-significant-byte occurs in lowest address.
+ | LittleEndian -- ^ least-significant-byte occurs in lowest address.
+ deriving (Eq, Ord, Bounded, Enum, Read, Show)
+
+-- | The byte ordering of the target machine.
+targetByteOrder :: ByteOrder
+#if defined(WORDS_BIGENDIAN)
+targetByteOrder = BigEndian
+#else
+targetByteOrder = LittleEndian
+#endif
diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal
index f00fb8768e..9429de05c3 100644
--- a/libraries/base/base.cabal
+++ b/libraries/base/base.cabal
@@ -202,6 +202,7 @@ Library
Foreign.Storable
GHC.Arr
GHC.Base
+ GHC.ByteOrder
GHC.Char
GHC.Conc
GHC.Conc.IO