module GHC.Driver.Config.HsToCore.Ticks
  ( initTicksConfig
  )
where

import GHC.Prelude

import Data.Maybe (catMaybes)

import GHC.Driver.Backend
import GHC.Driver.Session
import GHC.HsToCore.Ticks

initTicksConfig :: DynFlags -> TicksConfig
initTicksConfig :: DynFlags -> TicksConfig
initTicksConfig DynFlags
dflags = TicksConfig
  { ticks_passes :: [TickishType]
ticks_passes       = DynFlags -> [TickishType]
coveragePasses DynFlags
dflags
  , ticks_profAuto :: ProfAuto
ticks_profAuto     = DynFlags -> ProfAuto
profAuto DynFlags
dflags
  , ticks_countEntries :: Bool
ticks_countEntries = GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_ProfCountEntries DynFlags
dflags
  }

coveragePasses :: DynFlags -> [TickishType]
coveragePasses :: DynFlags -> [TickishType]
coveragePasses DynFlags
dflags = forall a. [Maybe a] -> [a]
catMaybes
  [ forall {a}. a -> Bool -> Maybe a
ifA TickishType
Breakpoints forall a b. (a -> b) -> a -> b
$ Backend -> Bool
backendWantsBreakpointTicks forall a b. (a -> b) -> a -> b
$ DynFlags -> Backend
backend DynFlags
dflags
  , forall {a}. a -> Bool -> Maybe a
ifA TickishType
HpcTicks forall a b. (a -> b) -> a -> b
$ GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_Hpc DynFlags
dflags
  , forall {a}. a -> Bool -> Maybe a
ifA TickishType
ProfNotes forall a b. (a -> b) -> a -> b
$ DynFlags -> Bool
sccProfilingEnabled DynFlags
dflags Bool -> Bool -> Bool
&& DynFlags -> ProfAuto
profAuto DynFlags
dflags forall a. Eq a => a -> a -> Bool
/= ProfAuto
NoProfAuto
  , forall {a}. a -> Bool -> Maybe a
ifA TickishType
SourceNotes forall a b. (a -> b) -> a -> b
$ DynFlags -> Bool
needSourceNotes DynFlags
dflags
  ]
  where ifA :: a -> Bool -> Maybe a
ifA a
x Bool
cond = if Bool
cond then forall a. a -> Maybe a
Just a
x else forall a. Maybe a
Nothing