Skip to content

Instantly share code, notes, and snippets.

@ndmitchell
Created August 24, 2015 20:20
Show Gist options
  • Save ndmitchell/e7cf2ff2b3f1cc3dc4e1 to your computer and use it in GitHub Desktop.
Save ndmitchell/e7cf2ff2b3f1cc3dc4e1 to your computer and use it in GitHub Desktop.
GHC compile
import GHC
import GHC.Paths ( libdir )
import DynFlags
import Linker
import Module
import Outputable
import Control.Monad.IO.Class
targetFile = "Test.hs"
main :: IO ()
main = do
res <- example
return ()
example =
defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
runGhc (Just libdir) $ do
{-
liftIO $ print "x"
let dflags2 = dflags { ghcLink = LinkBinary
, hscTarget = HscAsm
}
liftIO $ print "x"
let dflags' = foldl xopt_set dflags2
[Opt_Cpp, Opt_ImplicitPrelude, Opt_MagicHash]
liftIO $ print "x"
setSessionDynFlags dflags'
liftIO $ print "gusesing"
-}
dflags <- getSessionDynFlags
(dflags, _, _) <- parseDynamicFlags dflags []
setSessionDynFlags dflags{ghcMode=OneShot, hscTarget = HscAsm, ghcLink=LinkBinary} -- , verbosity=3}
setTargets [Target (TargetFile "Test.hs" Nothing) True Nothing]
load LoadAllTargets
shw (TargetModule x) = "Module " ++ "x"
shw (TargetFile x y) = "TargetFile " ++ show x ++ " " ++ show y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment