-- | Subsystem configuration
module GHC.Driver.Config
   ( initOptCoercionOpts
   , initSimpleOpts
   , initEvalOpts
   )
where

import GHC.Prelude

import GHC.Driver.DynFlags
import GHC.Core.SimpleOpt
import GHC.Core.Coercion.Opt
import GHCi.Message (EvalOpts(..))

-- | Initialise coercion optimiser configuration from DynFlags
initOptCoercionOpts :: DynFlags -> OptCoercionOpts
initOptCoercionOpts :: DynFlags -> OptCoercionOpts
initOptCoercionOpts DynFlags
dflags = OptCoercionOpts
   { optCoercionEnabled :: Bool
optCoercionEnabled = Bool -> Bool
not (DynFlags -> Bool
hasNoOptCoercion DynFlags
dflags)
   }

-- | Initialise Simple optimiser configuration from DynFlags
initSimpleOpts :: DynFlags -> SimpleOpts
initSimpleOpts :: DynFlags -> SimpleOpts
initSimpleOpts DynFlags
dflags = SimpleOpts
   { so_uf_opts :: UnfoldingOpts
so_uf_opts = DynFlags -> UnfoldingOpts
unfoldingOpts DynFlags
dflags
   , so_co_opts :: OptCoercionOpts
so_co_opts = DynFlags -> OptCoercionOpts
initOptCoercionOpts DynFlags
dflags
   , so_eta_red :: Bool
so_eta_red = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_DoEtaReduction DynFlags
dflags
   }

-- | Extract GHCi options from DynFlags and step
initEvalOpts :: DynFlags -> Bool -> EvalOpts
initEvalOpts :: DynFlags -> Bool -> EvalOpts
initEvalOpts DynFlags
dflags Bool
step =
  EvalOpts
    { useSandboxThread :: Bool
useSandboxThread = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_GhciSandbox DynFlags
dflags
    , singleStep :: Bool
singleStep       = Bool
step
    , breakOnException :: Bool
breakOnException = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_BreakOnException DynFlags
dflags
    , breakOnError :: Bool
breakOnError     = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_BreakOnError DynFlags
dflags
    }