module Metaplug.Initialize ( initSession, initSession', ) where import GHC as GHC import DynFlags import Metaplug.Types as T import System.FilePath initSession :: FilePath -> [String] -> SessionMode -> IO MetaSession initSession libpath args mode = defaultErrorHandler defaultDynFlags $ do s <- case mode of T.InteractiveMode -> do s' <- newSession GHC.Interactive $ Just libpath df <- setNewFlags s' args let df' = df{hscTarget=HscInterpreted} setSessionDynFlags s' df' return s' T.MakeMode -> do s' <- newSession GHC.BatchCompile $ Just libpath df <- setNewFlags s' args setSessionDynFlags s' df -- HscAsm is implied return s' f' <- getSessionDynFlags s return $ MetaSession { session = s, target = mode, sflags = f' } where setNewFlags :: Session -> [String] -> IO DynFlags setNewFlags sess av = do f <- getSessionDynFlags sess (f',un) <- parseDynamicFlags f av return f' initSession' :: FilePath -> [String] -> DynFlags -> SessionMode -> IO MetaSession initSession' libpath args flags mode = defaultErrorHandler defaultDynFlags $ do s <- case mode of T.InteractiveMode -> do s' <- newSession GHC.Interactive $ Just libpath setSessionDynFlags s' flags return s' T.MakeMode -> do s' <- newSession GHC.BatchCompile $ Just libpath setSessionDynFlags s' flags return s' f' <- getSessionDynFlags s return $ MetaSession { session = s, target = mode, sflags = f' }