summaryrefslogtreecommitdiff
path: root/libraries/ghc-boot/GHC
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2019-08-05 20:44:33 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-08-06 20:26:32 -0400
commit6f116005a144b3f09381e0a5967a364eb57a5aa5 (patch)
treee6fa10c5f1f37790d15dff2b9dce7c700b26366a /libraries/ghc-boot/GHC
parentc83e39bf91cfeb17a54ccfd5d01bfdfa1b4a72c9 (diff)
downloadhaskell-6f116005a144b3f09381e0a5967a364eb57a5aa5.tar.gz
Introduce a type for "platform word size", use it instead of Int
We introduce a PlatformWordSize type and use it in platformWordSize field. This removes to panic/error calls called when platform word size is not 32 or 64. We now check for this when reading the platform config.
Diffstat (limited to 'libraries/ghc-boot/GHC')
-rw-r--r--libraries/ghc-boot/GHC/Platform.hs38
1 files changed, 35 insertions, 3 deletions
diff --git a/libraries/ghc-boot/GHC/Platform.hs b/libraries/ghc-boot/GHC/Platform.hs
index 01d709a199..ea1aa5e323 100644
--- a/libraries/ghc-boot/GHC/Platform.hs
+++ b/libraries/ghc-boot/GHC/Platform.hs
@@ -1,9 +1,10 @@
-{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE LambdaCase, ScopedTypeVariables #-}
-- | A description of the platform we're compiling for.
--
module GHC.Platform (
Platform(..),
+ PlatformWordSize(..),
Arch(..),
OS(..),
ArmISA(..),
@@ -17,6 +18,8 @@ module GHC.Platform (
osMachOTarget,
osSubsectionsViaSymbols,
platformUsesFrameworks,
+ platformWordSizeInBytes,
+ platformWordSizeInBits,
PlatformMisc(..),
IntegerLibrary(..),
@@ -28,6 +31,7 @@ module GHC.Platform (
where
import Prelude -- See Note [Why do we import Prelude here?]
+import GHC.Read
-- | Contains enough information for the native code generator to emit
-- code for this platform.
@@ -37,7 +41,7 @@ data Platform
platformOS :: OS,
-- Word size in bytes (i.e. normally 4 or 8,
-- for 32bit and 64bit platforms respectively)
- platformWordSize :: {-# UNPACK #-} !Int,
+ platformWordSize :: PlatformWordSize,
platformUnregisterised :: Bool,
platformHasGnuNonexecStack :: Bool,
platformHasIdentDirective :: Bool,
@@ -46,6 +50,31 @@ data Platform
}
deriving (Read, Show, Eq)
+data PlatformWordSize
+ = PW4 -- ^ A 32-bit platform
+ | PW8 -- ^ A 64-bit platform
+ deriving (Eq)
+
+instance Show PlatformWordSize where
+ show PW4 = "4"
+ show PW8 = "8"
+
+instance Read PlatformWordSize where
+ readPrec = do
+ i :: Int <- readPrec
+ case i of
+ 4 -> return PW4
+ 8 -> return PW8
+ other -> fail ("Invalid PlatformWordSize: " ++ show other)
+
+platformWordSizeInBytes :: Platform -> Int
+platformWordSizeInBytes p =
+ case platformWordSize p of
+ PW4 -> 4
+ PW8 -> 8
+
+platformWordSizeInBits :: Platform -> Int
+platformWordSizeInBits p = platformWordSizeInBytes p * 8
-- | Architectures that the native code generator knows about.
-- TODO: It might be nice to extend these constructors with information
@@ -185,7 +214,10 @@ data PPC_64ABI
-- | This predicate tells us whether the platform is 32-bit.
target32Bit :: Platform -> Bool
-target32Bit p = platformWordSize p == 4
+target32Bit p =
+ case platformWordSize p of
+ PW4 -> True
+ PW8 -> False
-- | This predicate tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool