3 import qualified System.IO.Unsafe
7 import qualified GHC.Paths
8 import qualified DynFlags
10 -- Change a DynFlag from within the Ghc monad. Strangely enough there seems to
11 -- be no standard function to do exactly this.
12 setDynFlag :: DynFlags.DynFlag -> GHC.Ghc ()
14 dflags <- GHC.getSessionDynFlags
15 let dflags' = DynFlags.dopt_set dflags dflag
16 GHC.setSessionDynFlags dflags'
19 -- We don't want the IO monad sprinkled around everywhere, so we hide it.
20 -- This should be safe as long as we only do simple things in the GhcMonad
21 -- such as interface lookups and evaluating simple expressions that
22 -- don't have side effects themselves (Or rather, that don't use
23 -- unsafePerformIO themselves, since normal side effectful function would
24 -- just return an IO monad when they are evaluated).
25 unsafeRunGhc :: GHC.Ghc a -> a
27 System.IO.Unsafe.unsafePerformIO $
28 GHC.runGhc (Just GHC.Paths.libdir) $ do
29 dflags <- GHC.getSessionDynFlags
30 GHC.setSessionDynFlags dflags