Commit 92daad24 authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot
Browse files

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
parent 2707c4ea
......@@ -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
{-# 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
......@@ -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 ()
......
......@@ -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
......
......@@ -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"
......
......@@ -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"
......
{-# 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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment