diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-03-11 19:14:11 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-25 22:42:02 -0400 |
commit | 0de03cd78729dc58a846c64b645e71057ec5d24e (patch) | |
tree | 4d893f44db3fa94094376cf4fcad9a1a832ee261 /libraries/ghc-boot/GHC | |
parent | 262e42aa34c4d5705c8d011907c351497dd4e862 (diff) | |
download | haskell-0de03cd78729dc58a846c64b645e71057ec5d24e.tar.gz |
DynFlags refactoring III
Use Platform instead of DynFlags when possible:
* `tARGET_MIN_INT` et al. replaced with `platformMinInt` et al.
* no more DynFlags in PreRules: added a new `RuleOpts` datatype
* don't use `wORD_SIZE` in the compiler
* make `wordAlignment` use `Platform`
* make `dOUBLE_SIZE` a constant
Metric Decrease:
T13035
T1969
Diffstat (limited to 'libraries/ghc-boot/GHC')
-rw-r--r-- | libraries/ghc-boot/GHC/Platform.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libraries/ghc-boot/GHC/Platform.hs b/libraries/ghc-boot/GHC/Platform.hs index 341b551fc5..f6a7060b3f 100644 --- a/libraries/ghc-boot/GHC/Platform.hs +++ b/libraries/ghc-boot/GHC/Platform.hs @@ -21,6 +21,11 @@ module GHC.Platform ( platformUsesFrameworks, platformWordSizeInBytes, platformWordSizeInBits, + platformMinInt, + platformMaxInt, + platformMaxWord, + platformInIntRange, + platformInWordRange, PlatformMisc(..), IntegerLibrary(..), @@ -33,6 +38,8 @@ where import Prelude -- See Note [Why do we import Prelude here?] import GHC.Read +import Data.Word +import Data.Int -- | Contains the bare-bones arch and os information. This isn't enough for -- code gen, but useful for tasks where we can fall back upon the host @@ -305,3 +312,29 @@ data IntegerLibrary = IntegerGMP | IntegerSimple deriving (Read, Show, Eq) + +-- | Minimum representable Int value for the given platform +platformMinInt :: Platform -> Integer +platformMinInt p = case platformWordSize p of + PW4 -> toInteger (minBound :: Int32) + PW8 -> toInteger (minBound :: Int64) + +-- | Maximum representable Int value for the given platform +platformMaxInt :: Platform -> Integer +platformMaxInt p = case platformWordSize p of + PW4 -> toInteger (maxBound :: Int32) + PW8 -> toInteger (maxBound :: Int64) + +-- | Maximum representable Word value for the given platform +platformMaxWord :: Platform -> Integer +platformMaxWord p = case platformWordSize p of + PW4 -> toInteger (maxBound :: Word32) + PW8 -> toInteger (maxBound :: Word64) + +-- | Test if the given Integer is representable with a platform Int +platformInIntRange :: Platform -> Integer -> Bool +platformInIntRange platform x = x >= platformMinInt platform && x <= platformMaxInt platform + +-- | Test if the given Integer is representable with a platform Word +platformInWordRange :: Platform -> Integer -> Bool +platformInWordRange platform x = x >= 0 && x <= platformMaxWord platform |