Revert "Generate Typeable info at definition sites"
[ghc.git] / compiler / main / Hooks.hs
1 -- \section[Hooks]{Low level API hooks}
2
3 -- NB: this module is SOURCE-imported by DynFlags, and should primarily
4 -- refer to *types*, rather than *code*
5 -- If you import too muchhere , then the revolting compiler_stage2_dll0_MODULES
6 -- stuff in compiler/ghc.mk makes DynFlags link to too much stuff
7
8 module Hooks ( Hooks
9 , emptyHooks
10 , lookupHook
11 , getHooked
12 -- the hooks:
13 , dsForeignsHook
14 , tcForeignImportsHook
15 , tcForeignExportsHook
16 , hscFrontendHook
17 , hscCompileCoreExprHook
18 , ghcPrimIfaceHook
19 , runPhaseHook
20 , runMetaHook
21 , linkHook
22 , runRnSpliceHook
23 , getValueSafelyHook
24 ) where
25
26 import DynFlags
27 import Name
28 import PipelineMonad
29 import HscTypes
30 import HsDecls
31 import HsBinds
32 import HsExpr
33 import OrdList
34 import Id
35 import TcRnTypes
36 import Bag
37 import RdrName
38 import CoreSyn
39 import BasicTypes
40 import Type
41 import SrcLoc
42
43 import Data.Maybe
44
45 {-
46 ************************************************************************
47 * *
48 \subsection{Hooks}
49 * *
50 ************************************************************************
51 -}
52
53 -- | Hooks can be used by GHC API clients to replace parts of
54 -- the compiler pipeline. If a hook is not installed, GHC
55 -- uses the default built-in behaviour
56
57 emptyHooks :: Hooks
58 emptyHooks = Hooks Nothing Nothing Nothing Nothing Nothing
59 Nothing Nothing Nothing Nothing Nothing Nothing
60
61 data Hooks = Hooks
62 { dsForeignsHook :: Maybe ([LForeignDecl Id] -> DsM (ForeignStubs, OrdList (Id, CoreExpr)))
63 , tcForeignImportsHook :: Maybe ([LForeignDecl Name] -> TcM ([Id], [LForeignDecl Id], Bag GlobalRdrElt))
64 , tcForeignExportsHook :: Maybe ([LForeignDecl Name] -> TcM (LHsBinds TcId, [LForeignDecl TcId], Bag GlobalRdrElt))
65 , hscFrontendHook :: Maybe (ModSummary -> Hsc FrontendResult)
66 , hscCompileCoreExprHook :: Maybe (HscEnv -> SrcSpan -> CoreExpr -> IO HValue)
67 , ghcPrimIfaceHook :: Maybe ModIface
68 , runPhaseHook :: Maybe (PhasePlus -> FilePath -> DynFlags -> CompPipeline (PhasePlus, FilePath))
69 , runMetaHook :: Maybe (MetaHook TcM)
70 , linkHook :: Maybe (GhcLink -> DynFlags -> Bool -> HomePackageTable -> IO SuccessFlag)
71 , runRnSpliceHook :: Maybe (HsSplice Name -> RnM (HsSplice Name))
72 , getValueSafelyHook :: Maybe (HscEnv -> Name -> Type -> IO (Maybe HValue))
73 }
74
75 getHooked :: (Functor f, HasDynFlags f) => (Hooks -> Maybe a) -> a -> f a
76 getHooked hook def = fmap (lookupHook hook def) getDynFlags
77
78 lookupHook :: (Hooks -> Maybe a) -> a -> DynFlags -> a
79 lookupHook hook def = fromMaybe def . hook . hooks