diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-09-23 12:24:49 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-25 21:14:36 -0400 |
commit | 92daad241bf136a10346ecbf520d62921c82bf7d (patch) | |
tree | d5874746505a8de2b2f3ee479742fd9cefc5959f /libraries/ghc-bignum | |
parent | 2707c4eae4cf99e6da2709e128f560d91e468357 (diff) | |
download | haskell-92daad241bf136a10346ecbf520d62921c82bf7d.tar.gz |
Bignum: refactor backend modules
* move backends into GHC.Num.Backend.*
* split backend selection into GHC.Num.Backend and
GHC.Num.Backend.Selected to avoid duplication with the Check backend
Diffstat (limited to 'libraries/ghc-bignum')
-rw-r--r-- | libraries/ghc-bignum/ghc-bignum.cabal | 13 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend.hs | 15 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/Check.hs (renamed from libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs) | 16 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/FFI.hs (renamed from libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs) | 2 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs (renamed from libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs) | 2 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/Native.hs (renamed from libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs) | 2 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/Selected.hs | 24 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/BigNat.hs | 17 |
8 files changed, 53 insertions, 38 deletions
diff --git a/libraries/ghc-bignum/ghc-bignum.cabal b/libraries/ghc-bignum/ghc-bignum.cabal index 150ceabf51..bc478cf108 100644 --- a/libraries/ghc-bignum/ghc-bignum.cabal +++ b/libraries/ghc-bignum/ghc-bignum.cabal @@ -66,15 +66,12 @@ library default-language: Haskell2010 other-extensions: BangPatterns - CApiFFI CPP - DeriveDataTypeable ExplicitForAll GHCForeignImportPrim MagicHash NegativeLiterals NoImplicitPrelude - StandaloneDeriving UnboxedTuples UnliftedFFITypes ForeignFunctionInterface @@ -97,14 +94,14 @@ library if flag(gmp) cpp-options: -DBIGNUM_GMP other-modules: - GHC.Num.BigNat.GMP + GHC.Num.Backend.GMP c-sources: cbits/gmp_wrappers.c if flag(ffi) cpp-options: -DBIGNUM_FFI other-modules: - GHC.Num.BigNat.FFI + GHC.Num.Backend.FFI if flag(native) cpp-options: -DBIGNUM_NATIVE @@ -112,13 +109,15 @@ library if flag(check) cpp-options: -DBIGNUM_CHECK other-modules: - GHC.Num.BigNat.Check + GHC.Num.Backend.Check exposed-modules: GHC.Num.Primitives GHC.Num.WordArray GHC.Num.BigNat - GHC.Num.BigNat.Native + GHC.Num.Backend + GHC.Num.Backend.Selected + GHC.Num.Backend.Native GHC.Num.Natural GHC.Num.Integer diff --git a/libraries/ghc-bignum/src/GHC/Num/Backend.hs b/libraries/ghc-bignum/src/GHC/Num/Backend.hs new file mode 100644 index 0000000000..285be2a703 --- /dev/null +++ b/libraries/ghc-bignum/src/GHC/Num/Backend.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE NoImplicitPrelude #-} + +-- | Selected backend +module GHC.Num.Backend + ( module Backend + ) +where + +#if defined(BIGNUM_CHECK) +import GHC.Num.Backend.Check as Backend +#else +import GHC.Num.Backend.Selected as Backend +#endif + diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/Check.hs index 8431a5564d..73f8366ad0 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/Check.hs @@ -10,25 +10,17 @@ {-# OPTIONS_GHC -Wno-name-shadowing #-} -- | Check Native implementation against another backend -module GHC.Num.BigNat.Check where +module GHC.Num.Backend.Check where import GHC.Prim import GHC.Types import GHC.Num.WordArray import GHC.Num.Primitives -import qualified GHC.Num.BigNat.Native as Native +import qualified GHC.Num.Backend.Native as Native +import qualified GHC.Num.Backend.Selected as Other #if defined(BIGNUM_NATIVE) -#error You can't validate Native backed against itself. Choose another backend (e.g. gmp, ffi) - -#elif defined(BIGNUM_FFI) -import qualified GHC.Num.BigNat.FFI as Other - -#elif defined(BIGNUM_GMP) -import qualified GHC.Num.BigNat.GMP as Other - -#else -#error Undefined BigNat backend. Use a flag to select it (e.g. gmp, native, ffi)` +#error You can't validate Native backend against itself. Choose another backend (e.g. gmp, ffi) #endif default () diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/FFI.hs index cfd96be7a0..a049cfe332 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/FFI.hs @@ -13,7 +13,7 @@ -- that replace bignat foreign calls with calls to the native platform bignat -- library (e.g. JavaScript's BigInt). You can also link an extra object -- providing the implementation. -module GHC.Num.BigNat.FFI where +module GHC.Num.Backend.FFI where import GHC.Prim import GHC.Types diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs index 35d3983313..a340db573e 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs @@ -13,7 +13,7 @@ -- -- This has been adapted from the legacy `integer-gmp` package written by -- Herbert Valerio Riedel. -module GHC.Num.BigNat.GMP where +module GHC.Num.Backend.GMP where #include "MachDeps.h" #include "WordSize.h" diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/Native.hs index 5c1baa4398..1169af41d6 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/Native.hs @@ -9,7 +9,7 @@ {-# LANGUAGE BinaryLiterals #-} {-# OPTIONS_GHC -Wno-name-shadowing #-} -module GHC.Num.BigNat.Native where +module GHC.Num.Backend.Native where #include "MachDeps.h" #include "WordSize.h" diff --git a/libraries/ghc-bignum/src/GHC/Num/Backend/Selected.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/Selected.hs new file mode 100644 index 0000000000..f0ffd86220 --- /dev/null +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/Selected.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE NoImplicitPrelude #-} + +-- | Selected backend +-- +-- We need this module in addition to GHC.Num.Backend to avoid module loops with +-- Check backend. +module GHC.Num.Backend.Selected + ( module Backend + ) +where + +#if defined(BIGNUM_NATIVE) +import GHC.Num.Backend.Native as Backend + +#elif defined(BIGNUM_FFI) +import GHC.Num.Backend.FFI as Backend + +#elif defined(BIGNUM_GMP) +import GHC.Num.Backend.GMP as Backend + +#else +#error Undefined BigNum backend. Use a flag to select it (e.g. gmp, native, ffi)` +#endif diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat.hs index e38c807ede..f2d9e58e17 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat.hs +++ b/libraries/ghc-bignum/src/GHC/Num/BigNat.hs @@ -23,27 +23,12 @@ import GHC.Classes import GHC.Magic import GHC.Num.Primitives import GHC.Num.WordArray +import GHC.Num.Backend #if WORD_SIZE_IN_BITS < 64 import GHC.IntWord64 #endif -#if defined(BIGNUM_CHECK) -import GHC.Num.BigNat.Check - -#elif defined(BIGNUM_NATIVE) -import GHC.Num.BigNat.Native - -#elif defined(BIGNUM_FFI) -import GHC.Num.BigNat.FFI - -#elif defined(BIGNUM_GMP) -import GHC.Num.BigNat.GMP - -#else -#error Undefined BigNat backend. Use a flag to select it (e.g. gmp, native, ffi)` -#endif - default () -- | A BigNat |