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

import GHC.Prelude

import GHC.Driver.Session
import GHC.Core.SimpleOpt
import GHC.Core.Coercion.Opt
import GHC.Parser.Lexer

-- | 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
   }

-- | Extracts the flag information needed for parsing
initParserOpts :: DynFlags -> ParserOpts
initParserOpts :: DynFlags -> ParserOpts
initParserOpts =
  EnumSet WarningFlag
-> EnumSet Extension -> Bool -> Bool -> Bool -> Bool -> ParserOpts
mkParserOpts
    (EnumSet WarningFlag
 -> EnumSet Extension -> Bool -> Bool -> Bool -> Bool -> ParserOpts)
-> (DynFlags -> EnumSet WarningFlag)
-> DynFlags
-> EnumSet Extension
-> Bool
-> Bool
-> Bool
-> Bool
-> ParserOpts
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DynFlags -> EnumSet WarningFlag
warningFlags
    (DynFlags
 -> EnumSet Extension -> Bool -> Bool -> Bool -> Bool -> ParserOpts)
-> (DynFlags -> EnumSet Extension)
-> DynFlags
-> Bool
-> Bool
-> Bool
-> Bool
-> ParserOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DynFlags -> EnumSet Extension
extensionFlags
    (DynFlags -> Bool -> Bool -> Bool -> Bool -> ParserOpts)
-> (DynFlags -> Bool)
-> DynFlags
-> Bool
-> Bool
-> Bool
-> ParserOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DynFlags -> Bool
safeImportsOn
    (DynFlags -> Bool -> Bool -> Bool -> ParserOpts)
-> (DynFlags -> Bool) -> DynFlags -> Bool -> Bool -> ParserOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_Haddock
    (DynFlags -> Bool -> Bool -> ParserOpts)
-> (DynFlags -> Bool) -> DynFlags -> Bool -> ParserOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_KeepRawTokenStream
    (DynFlags -> Bool -> ParserOpts)
-> (DynFlags -> Bool) -> DynFlags -> ParserOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> DynFlags -> Bool
forall a b. a -> b -> a
const Bool
True