Adaptor layer for GHC API.
This commit is contained in:
61
Types.hs
61
Types.hs
@@ -2,16 +2,6 @@
|
||||
|
||||
module Types where
|
||||
|
||||
import Control.Monad
|
||||
import CoreMonad
|
||||
import DynFlags
|
||||
import ErrMsg
|
||||
import Exception
|
||||
import GHC
|
||||
import GHC.Paths (libdir)
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
data OutputStyle = LispStyle | PlainStyle
|
||||
|
||||
data Options = Options {
|
||||
@@ -22,6 +12,7 @@ data Options = Options {
|
||||
}
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
convert :: ToString a => Options -> a -> String
|
||||
convert Options{ outputStyle = LispStyle } = toLisp
|
||||
convert Options{ outputStyle = PlainStyle } = toPlain
|
||||
@@ -56,53 +47,3 @@ quote x = "\"" ++ x ++ "\""
|
||||
|
||||
addNewLine :: String -> String
|
||||
addNewLine = (++ "\n")
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
withGHC :: (MonadPlus m) => Ghc (m a) -> IO (m a)
|
||||
withGHC body = ghandle ignore $ runGhc (Just libdir) body
|
||||
where
|
||||
ignore :: (MonadPlus m) => SomeException -> IO (m a)
|
||||
ignore _ = return mzero
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
initSession0 :: Options -> Ghc [PackageId]
|
||||
initSession0 opt = getSessionDynFlags >>=
|
||||
(>>= setSessionDynFlags) . setGhcFlags opt
|
||||
|
||||
initSession :: Options -> [String] -> [FilePath] -> Bool -> Ghc LogReader
|
||||
initSession opt cmdOpts idirs logging = do
|
||||
dflags <- getSessionDynFlags
|
||||
let opts = map noLoc cmdOpts
|
||||
(dflags',_,_) <- parseDynamicFlags dflags opts
|
||||
(dflags'',readLog) <- liftIO . (>>= setLogger logging) . setGhcFlags opt . setFlags dflags' $ idirs
|
||||
setSessionDynFlags dflags''
|
||||
return readLog
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
setFlags :: DynFlags -> [FilePath] -> DynFlags
|
||||
setFlags d idirs = d'
|
||||
where
|
||||
d' = d {
|
||||
packageFlags = ghcPackage : packageFlags d
|
||||
, importPaths = idirs
|
||||
, ghcLink = NoLink
|
||||
, hscTarget = HscInterpreted
|
||||
}
|
||||
|
||||
ghcPackage :: PackageFlag
|
||||
ghcPackage = ExposePackage "ghc"
|
||||
|
||||
setGhcFlags :: Monad m => Options -> DynFlags -> m DynFlags
|
||||
setGhcFlags opt flagset =
|
||||
do (flagset',_,_) <- parseDynamicFlags flagset (map noLoc (ghcOpts opt))
|
||||
return flagset'
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
setTargetFile :: (GhcMonad m) => String -> m ()
|
||||
setTargetFile file = do
|
||||
target <- guessTarget file Nothing
|
||||
setTargets [target]
|
||||
|
||||
Reference in New Issue
Block a user