GHC API lets you process Haskell sources, and (among other) specify code generation and linking level. For example:
- (1) no codegen & no link
- (2) bytecode generation & link in memory
- (3) machine code generation & linking output binaries
For code analysis purposes, based on generating the typechecked AST, option (1) suffices most of the time. There are some situations in which it doesn't:
- TemplateHaskell (TH) splice needs to execute code (at compile time) from an imported module: the imported module must be available in compiled form, so either (2) or (3) is needed. Example: in
$([|$(foo)|])
,foo
will be evaluated at compile-time. - Code uses FFI imports. For this one would expect that (2) is needed (see
checkCOrAsmOrLlvmOrInterp
inTcForeign.hs
), but actually unless it is used (say by TH, see below), even (1) works too (see the wrappercheckCg
).