diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-12-10 20:41:53 -0800 |
---|---|---|
committer | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-12-12 00:38:47 -0800 |
commit | a3c2a26b3af034f09c960b2dad38f73be7e3a655 (patch) | |
tree | 74efe130fc04633aebfe6f022689089fd2a8318d /ghc | |
parent | 779dfea1d9cc713d9b1e26bb559e8da309b2aeec (diff) | |
download | haskell-a3c2a26b3af034f09c960b2dad38f73be7e3a655.tar.gz |
Frontend plugins.
Summary:
Frontend plugins enable users to write plugins to replace
GHC major modes. E.g. instead of saying
ghc --make A B C
a user can now say
ghc --frontend GHC.Frontend.Shake A B C
which might provide an alternative implementation of a multi-module
build. For more details, see the manual entry.
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate
Reviewers: simonmar, bgamari, austin, simonpj
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1598
GHC Trac Issues: #11194
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/Main.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ghc/Main.hs b/ghc/Main.hs index d14a897dc7..c85f0b3a8b 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -28,6 +28,13 @@ import DriverMkDepend ( doMkDependHS ) import InteractiveUI ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings ) #endif +-- Frontend plugins +#ifdef GHCI +import DynamicLoading +import Plugins +#endif +import Module ( ModuleName ) + -- Various other random stuff that we need import Config @@ -253,6 +260,7 @@ main' postLoadMode dflags0 args flagWarnings = do DoEval exprs -> ghciUI srcs $ Just $ reverse exprs DoAbiHash -> abiHash (map fst srcs) ShowPackages -> liftIO $ showPackages dflags6 + DoFrontend f -> doFrontend f srcs liftIO $ dumpFinalStats dflags6 @@ -457,6 +465,7 @@ data PostLoadMode | DoEval [String] -- ghc -e foo -e bar => DoEval ["bar", "foo"] | DoAbiHash -- ghc --abi-hash | ShowPackages -- ghc --show-packages + | DoFrontend ModuleName -- ghc --frontend Plugin.Module doMkDependHSMode, doMakeMode, doInteractiveMode, doAbiHashMode, showPackagesMode :: Mode @@ -475,6 +484,9 @@ stopBeforeMode phase = mkPostLoadMode (StopBefore phase) doEvalMode :: String -> Mode doEvalMode str = mkPostLoadMode (DoEval [str]) +doFrontendMode :: String -> Mode +doFrontendMode str = mkPostLoadMode (DoFrontend (mkModuleName str)) + mkPostLoadMode :: PostLoadMode -> Mode mkPostLoadMode = Right . Right @@ -607,6 +619,7 @@ mode_flags = , defFlag "-interactive" (PassFlag (setMode doInteractiveMode)) , defFlag "-abi-hash" (PassFlag (setMode doAbiHashMode)) , defFlag "e" (SepArg (\s -> setMode (doEvalMode s) "-e")) + , defFlag "-frontend" (SepArg (\s -> setMode (doFrontendMode s) "-frontend")) ] setMode :: Mode -> String -> EwM ModeM () @@ -830,6 +843,20 @@ dumpPackages dflags = putMsg dflags (pprPackages dflags) dumpPackagesSimple dflags = putMsg dflags (pprPackagesSimple dflags) -- ----------------------------------------------------------------------------- +-- Frontend plugin support + +doFrontend :: ModuleName -> [(String, Maybe Phase)] -> Ghc () +#ifndef GHCI +doFrontend _ _ = + throwGhcException (CmdLineError "not built for interactive use") +#else +doFrontend modname srcs = do + hsc_env <- getSession + frontend_plugin <- liftIO $ loadFrontendPlugin hsc_env modname + frontend frontend_plugin (frontendPluginOpts (hsc_dflags hsc_env)) srcs +#endif + +-- ----------------------------------------------------------------------------- -- ABI hash support {- |