Created
November 19, 2021 14:13
-
-
Save ckoparkar/b83194ef7d36128c5c48035de342a777 to your computer and use it in GitHub Desktop.
Part of a GHC plugin which prints out all definitions it has access to.
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
installPlugin :: [GHC.CommandLineOption] -> [GHC.CoreToDo] | |
-> GHC.CoreM [GHC.CoreToDo] | |
installPlugin _ todos = return (testCoreTodo : todos) | |
where | |
testCoreTodo :: GHC.CoreToDo | |
testCoreTodo = GHC.CoreDoPluginPass "TEST" test | |
test :: GHC.ModGuts -> GHC.CoreM GHC.ModGuts | |
test mod_guts = do | |
hsc_env <- GHC.getHscEnv | |
external_package_state <- GHC.liftIO $ GHC.hscEPS hsc_env | |
let all_ids = GHC.nameEnvElts (GHC.eps_PTE external_package_state) | |
all_unfoldings = | |
(map (\tyt -> case tyt of | |
GHC.AnId i -> | |
Just (i, GHC.maybeUnfoldingTemplate | |
(GHC.realIdUnfolding i)) | |
_ -> Nothing) | |
all_ids) | |
GHC.putMsg (GHC.ppr all_unfoldings) | |
pure mod_guts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment