GHC can dump its optimized intermediate code (said to be in “Core” format) to a file as a side-effect of compilation. Core files, which are given the suffix .hcr, can be read and processed by non-GHC back-end tools. The Core format is formally described in An External Representation for the GHC Core Language, and sample tools (in Haskell) for manipulating Core files are available in the GHC source distribution directory /fptools/ghc/utils/ext-core. Note that the format of .hcr files is different (though similar) to the Core output format generated for debugging purposes (Section 4.18).
Generate .hcr files.