GHC can dump its optimized intermediate code (said to be in “Core” format)
to a file as a side-effect of compilation. Non-GHC back-end tools can read and process Core files; these files have the suffix
.hcr. The Core format is described in
An External Representation for the GHC Core Language,
and sample tools
for manipulating Core files (in Haskell) are available in the
extcore package on Hackage. Note that the format of
files is different from the Core output format that GHC generates
for debugging purposes (Section 4.19, “Debugging the compiler”), though the two formats appear somewhat similar.
The Core format natively supports notes which you can add to
your source code using the
CORE pragma (see Section 7.20, “Pragmas”).
Currently (as of version 6.8.2), GHC does not have the ability to read in External Core files as source. If you would like GHC to have this ability, please make your wishes known to the GHC Team.