module GHC.Driver.Config.CoreToStg.Prep
  ( initCorePrepConfig
  , initCorePrepPgmConfig
  ) where

import GHC.Prelude

import GHC.Core.Opt.Pipeline.Types ( CoreToDo(..) )
import GHC.Driver.Env
import GHC.Driver.Session
import GHC.Driver.Config.Core.Lint
import GHC.Driver.Config.Core.Opt.Arity
import GHC.Tc.Utils.Env
import GHC.Types.Var
import GHC.Utils.Outputable ( alwaysQualify )

import GHC.CoreToStg.Prep

initCorePrepConfig :: HscEnv -> IO CorePrepConfig
initCorePrepConfig :: HscEnv -> IO CorePrepConfig
initCorePrepConfig HscEnv
hsc_env = do
   let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
   convertNumLit <- do
     let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
         home_unit :: HomeUnit
home_unit = HscEnv -> HomeUnit
hsc_home_unit HscEnv
hsc_env
         lookup_global :: Name -> IO TyThing
lookup_global = HscEnv -> Name -> IO TyThing
lookupGlobal HscEnv
hsc_env
     Platform
-> HomeUnit
-> (Name -> IO TyThing)
-> IO (LitNumType -> Integer -> Maybe CoreExpr)
mkConvertNumLiteral Platform
platform HomeUnit
home_unit Name -> IO TyThing
lookup_global
   return $ CorePrepConfig
      { cp_catchNonexhaustiveCases = gopt Opt_CatchNonexhaustiveCases dflags
      , cp_convertNumLit = convertNumLit
      , cp_arityOpts = if gopt Opt_DoCleverArgEtaExpansion dflags
                       then Just (initArityOpts dflags)
                       else Nothing
      }

initCorePrepPgmConfig :: DynFlags -> [Var] -> CorePrepPgmConfig
initCorePrepPgmConfig :: DynFlags -> [Var] -> CorePrepPgmConfig
initCorePrepPgmConfig DynFlags
dflags [Var]
extra_vars = CorePrepPgmConfig
  { cpPgm_endPassConfig :: EndPassConfig
cpPgm_endPassConfig     = DynFlags -> [Var] -> NamePprCtx -> CoreToDo -> EndPassConfig
initEndPassConfig DynFlags
dflags [Var]
extra_vars NamePprCtx
alwaysQualify CoreToDo
CorePrep
  , cpPgm_generateDebugInfo :: Bool
cpPgm_generateDebugInfo = DynFlags -> Bool
needSourceNotes DynFlags
dflags
  }