Ignore .swp files.
[matthijs/master-project/cλash.git] / GhcTools.hs
1 module GhcTools where
2 -- Standard modules
3 import qualified System.IO.Unsafe
4
5 -- GHC API
6 import qualified GHC
7 import qualified GHC.Paths
8 import qualified DynFlags
9
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 ()
13 setDynFlag dflag = do
14   dflags <- GHC.getSessionDynFlags
15   let dflags' = DynFlags.dopt_set dflags dflag
16   GHC.setSessionDynFlags dflags'
17   return ()
18
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
26 unsafeRunGhc m =
27   System.IO.Unsafe.unsafePerformIO $ 
28       GHC.runGhc (Just GHC.Paths.libdir) $ do
29         dflags <- GHC.getSessionDynFlags
30         GHC.setSessionDynFlags dflags
31         m