rewire-frontend-2.8: A Haskell-to-Verilog/VHDL compiler, front end (GHC driver, Eidos, Synolon)
Safe HaskellTrustworthy
LanguageHaskell2010

ReWire.GHC.Session

Description

The GHC-driven front end, part one: an in-process GHC session that drives parse -> rename -> typecheck -> desugar over the whole home module graph and hands back the (-O0, pre-simplifier) desugared Core, one ModGuts per home module in dependency order.

Wrinkles this module exists to handle:

  • The desugarer runs GHC's simple optimizer unconditionally, and its occurrence analysis drops top-level binds unreachable from an exported binder -- even at -O0. A file with no module header is implicitly module Main (main) where, so everything but main would vanish. ensureLiveExports rewrites the parsed module before typechecking: headerless modules become export-all.
  • mg_binds is strictly per-module: the target's guts contain no code from imported modules (including all of rewire-user, compiled from source via the loadpath). So every home module is desugared, not just the target.
  • GHC reports errors as SourceError exceptions (from the per-module phases) or through the log action (during load); warnings only via the log action. Both are re-routed through ReWire's AstError / warnAt machinery so -w/-Werror and the usual error formatting (filename included) keep working.
Synopsis

Documentation

loadCore :: (MonadError AstError m, MonadIO m) => Config -> FilePath -> m [ModGuts] Source #

Load fp (and, recursively, its imports from the loadpath) through GHC, returning the -O0 desugared Core of every home module. GHC errors are re-raised as AstErrors; GHC warnings are re-emitted through warnAt.

dumpCore :: (MonadError AstError m, MonadIO m) => Config -> FilePath -> m () Source #

Load Core for the whole home module graph and dump it (a per-module binder summary; the full Core under -v). For debugging the session.