ghc-mod/Types.hs

55 lines
1.5 KiB
Haskell
Raw Normal View History

2010-04-30 09:36:31 +00:00
module Types where
2010-11-12 07:27:50 +00:00
import Control.Monad
import DynFlags
2010-04-30 09:36:31 +00:00
import Exception
import GHC
import GHC.Paths (libdir)
2010-11-12 07:27:50 +00:00
----------------------------------------------------------------
2010-04-30 09:36:31 +00:00
data Options = Options {
convert :: [String] -> String
, hlintOpts :: [String]
2011-01-27 05:29:39 +00:00
, operators :: Bool
2010-04-30 09:36:31 +00:00
}
2010-11-12 07:27:50 +00:00
withGHC :: (MonadPlus m) => Ghc (m a) -> IO (m a)
2010-04-30 09:36:31 +00:00
withGHC body = ghandle ignore $ runGhc (Just libdir) body
where
2010-11-12 07:27:50 +00:00
ignore :: (MonadPlus m) => SomeException -> IO (m a)
ignore _ = return mzero
----------------------------------------------------------------
2010-04-30 09:36:31 +00:00
initSession0 :: Ghc [PackageId]
initSession0 = getSessionDynFlags >>= setSessionDynFlags
2010-11-12 07:27:50 +00:00
2011-05-24 07:00:47 +00:00
initSession :: [String] -> Maybe [FilePath] -> Ghc [PackageId]
initSession cmdOpts midirs = do
2010-11-12 07:27:50 +00:00
dflags <- getSessionDynFlags
let opts = map noLoc cmdOpts
(dflags',_,_) <- parseDynamicFlags dflags opts
2011-05-24 07:00:47 +00:00
setSessionDynFlags $ setFlags dflags' midirs
2010-11-12 07:27:50 +00:00
----------------------------------------------------------------
2011-05-24 07:00:47 +00:00
setFlags :: DynFlags -> Maybe [FilePath] -> DynFlags
setFlags d midirs = maybe d' (\x -> d' { importPaths = x }) midirs
where
d' = d {
packageFlags = ghcPackage : packageFlags d
, ghcLink = NoLink
, hscTarget = HscInterpreted
}
2010-11-12 07:27:50 +00:00
ghcPackage :: PackageFlag
ghcPackage = ExposePackage "ghc"
----------------------------------------------------------------
setTargetFile :: (GhcMonad m) => String -> m ()
setTargetFile file = do
target <- guessTarget file Nothing
setTargets [target]