diff options
Diffstat (limited to 'testsuite/tests/plugins/hooks-plugin/Hooks/PhasePlugin.hs')
-rw-r--r-- | testsuite/tests/plugins/hooks-plugin/Hooks/PhasePlugin.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/plugins/hooks-plugin/Hooks/PhasePlugin.hs b/testsuite/tests/plugins/hooks-plugin/Hooks/PhasePlugin.hs new file mode 100644 index 0000000000..51cff77404 --- /dev/null +++ b/testsuite/tests/plugins/hooks-plugin/Hooks/PhasePlugin.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE GADTs #-} +{-# OPTIONS_GHC -Wall #-} +module Hooks.PhasePlugin (plugin) where + +import GHC.Plugins +import GHC.Driver.Hooks +import GHC.Tc.Utils.Monad +import GHC.Driver.Pipeline.Execute +import GHC.Driver.Pipeline.Phases +import System.IO + +plugin :: Plugin +plugin = defaultPlugin { driverPlugin = hooksP } + +hooksP :: [CommandLineOption] -> HscEnv -> IO HscEnv +hooksP opts hsc_env = do + hSetBuffering stdout NoBuffering + let hooks = hsc_hooks hsc_env + hooks' = hooks { runPhaseHook = Just fakeRunPhaseHook } + hsc_env' = hsc_env { hsc_hooks = hooks' } + return hsc_env' + +fakeRunPhaseHook :: PhaseHook +fakeRunPhaseHook = PhaseHook $ \tPhase -> do + liftIO $ case tPhase of + T_Cpp{} -> putStrLn "Cpp hook fired" + T_Hsc{} -> putStrLn "Hsc hook fired" + T_FileArgs{} -> putStrLn "FileArgs hook fired" + _ -> pure () + runPhase tPhase |