Skip to content

Instantly share code, notes, and snippets.

@ckoparkar
Created November 19, 2021 14:13
Show Gist options
  • Save ckoparkar/b83194ef7d36128c5c48035de342a777 to your computer and use it in GitHub Desktop.
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.
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 &lt- GHC.getHscEnv
external_package_state &lt- 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