Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steshaw/138b33730d62ae8deb814ccffb4cf616 to your computer and use it in GitHub Desktop.
Save steshaw/138b33730d62ae8deb814ccffb4cf616 to your computer and use it in GitHub Desktop.
Simple GHC API executable
module Main where
import Lib
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