| Version 4 (modified by simonpj, 7 years ago) |
|---|
GHC Commentary: The Compiler
The compiler itself is written entirely in Haskell, and lives in the many sub-directories of the compiler directory. Here is a block diagram of its top-level structure:
Contents
- Compiler Module Dependencies (deals with the arcane mutual recursions among GHC's many data types)
- Coding guidelines
- Compiling one module: HscMain
- Key data types (Simon PJ's diagram is attached at the bottom of this document):
- The source language: HsSyn
- RdrNames, Modules, and OccNames
- Names
- Entities: variables, type constructors, data constructors, and classes.
- Types: Type and Kind, equality types and coercions
- The core language
- The STG language
- The Cmm language
- ModIface?, ModDetails?, ModGuts?
- Passes:
- Renamer
- Typechecker
- Desugarer
- Core->core
- Core->CorePrep?
- CorePrep->Stg?
- The code generator: Stg->Cmm
- The GHC API
- Symbol names and the Z-encoding
- Template Haskell?
- Wired-in and known-key things
- Packages
- The Finder?
- Backends:
The GHC API is the interface exported by compiler/main/GHC.hs. To compile a Haskell module that uses the GHC API, use the flag -package ghc (in GHC 6.6 and later). GHC itself contains a few front-ends:
- The "one-shot" mode, where GHC compiles each file on the command line separately (eg. ghc -c Foo.hs). This mode is implemented directly on top of HscMain, since it compiles only one file at a time. In fact, this is all that GHC consisted of prior to version 5.00 when GHCi and --make were introduced.
- GHCi, the interactive environment, is implemented in compiler/ghci/InteractiveUI.hs and sits squarely on top of the GHC API.
- --make is almost a trivial client of the GHC API, and is implemented in compiler/main/Main.hs.
- -M, the Makefile dependency generator, is also a client of the GHC API and is implemented in compiler/main/DriverMkDepend.hs.
Note that since GHC is packaged as a single binary, all of these front-ends are present, and there is a single command-line interface implemented in compiler/main/Main.hs.
Attachments
-
ghc-top.png
(35.8 KB) - added by simonmar
7 years ago.

