-
-
Save chrisdone/6fcb9f1cba6324148d481fcd4eab6af6 to your computer and use it in GitHub Desktop.
ghc api demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE CPP #-} | |
import GHC | |
import GHC.Paths | |
import DynFlags | |
import Language.Haskell.TH.LanguageExtensions | |
targetFile :: [Char] | |
targetFile = "B.hs" | |
main :: IO () | |
main = do | |
defaultErrorHandler defaultFatalMessager defaultFlushOut $ do | |
runGhc (Just libdir) $ do | |
dflags <- getSessionDynFlags | |
let dflags' = foldl xopt_set dflags [ImplicitPrelude] | |
_ <- setSessionDynFlags dflags' | |
target <- guessTarget targetFile Nothing | |
setTargets [target] | |
_ <- load LoadAllTargets | |
modSum <- getModSummary $ mkModuleName "B" | |
p <- parseModule modSum | |
t <- typecheckModule p | |
pure () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment