Skip to content

Instantly share code, notes, and snippets.

@mpickering
Last active September 19, 2019 13:10
Show Gist options
  • Save mpickering/e13f343f2b35b51693d15582180b1c02 to your computer and use it in GitHub Desktop.
Save mpickering/e13f343f2b35b51693d15582180b1c02 to your computer and use it in GitHub Desktop.
Simple GHC API executable
module Main where
import GHC as G
import GhcMake as G
import DynFlags
import SrcLoc as G
import GHC.Paths
import Control.Monad
import Control.Monad.IO.Class
import System.Environment
initGhcM :: [String] -> Ghc ()
initGhcM xs = do
df1 <- getSessionDynFlags
let cmdOpts = ["-package", "ghc", "-fforce-recomp"] ++ xs
(df2, leftovers, warns) <- G.parseDynamicFlags df1 (map G.noLoc cmdOpts)
-- pprTraceM "leftovers" $ ppr leftovers
setSessionDynFlags df2
ts <- mapM (flip G.guessTarget Nothing) $ map unLoc leftovers
-- (df2, ts)
setTargets ts
-- mod_graph <- G.depanal [] True
void $ G.load LoadAllTargets -- Nothing mod_graph
-- df <- getSessionDynFlags
return ()
main :: IO ()
main = do
xs <- getArgs
runGhc (Just libdir) $ initGhcM xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment