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 {
|
2010-06-14 02:56:35 +00:00
|
|
|
convert :: [String] -> String
|
|
|
|
, hlintOpts :: [String]
|
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
|
|
|
|
|
|
|
initSession :: [String] -> Ghc [PackageId]
|
|
|
|
initSession cmdOpts = do
|
|
|
|
dflags <- getSessionDynFlags
|
|
|
|
let opts = map noLoc cmdOpts
|
|
|
|
(dflags',_,_) <- parseDynamicFlags dflags opts
|
|
|
|
setSessionDynFlags $ setFlags dflags'
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
setFlags :: DynFlags -> DynFlags
|
|
|
|
setFlags d = d {
|
|
|
|
importPaths = importPaths d ++ importDirs
|
|
|
|
, packageFlags = ghcPackage : packageFlags d
|
|
|
|
, ghcLink = NoLink
|
|
|
|
-- GHC.desugarModule does not produces the pattern warnings, why?
|
|
|
|
-- , hscTarget = HscNothing
|
|
|
|
, hscTarget = HscInterpreted
|
|
|
|
}
|
|
|
|
|
|
|
|
importDirs :: [String]
|
|
|
|
importDirs = ["..","../..","../../..","../../../../.."]
|
|
|
|
|
|
|
|
ghcPackage :: PackageFlag
|
|
|
|
ghcPackage = ExposePackage "ghc"
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
setTargetFile :: (GhcMonad m) => String -> m ()
|
|
|
|
setTargetFile file = do
|
|
|
|
target <- guessTarget file Nothing
|
|
|
|
setTargets [target]
|