|
CONVERSION ERROR
|
|
# GHC Commentary: The Compiler
|
|
|
|
|
|
Error: HttpError (HttpExceptionRequest Request {
|
|
|
|
host = "ghc.haskell.org"
|
|
The compiler itself is written entirely in Haskell, and lives in the many sub-directories of the [compiler](/trac/ghc/browser/ghc/compiler) directory.
|
|
port = 443
|
|
|
|
secure = True
|
|
- [Compiler Module Dependencies](module-dependencies) (deals with the arcane mutual recursions among GHC's many data types)
|
|
requestHeaders = []
|
|
- [Coding guidelines](commentary/coding-style)
|
|
path = "/trac/ghc/wiki/Commentary/Compiler"
|
|
|
|
queryString = "?version=5"
|
|
- [Key data types](commentary/compiler/key-data-types)
|
|
method = "GET"
|
|
- [Compiling one module: HscMain](commentary/compiler/hsc-main)
|
|
proxy = Nothing
|
|
|
|
rawBody = False
|
|
- [Renamer](commentary/compiler/renamer)
|
|
redirectCount = 10
|
|
- Typechecker
|
|
responseTimeout = ResponseTimeoutDefault
|
|
- Desugarer
|
|
requestVersion = HTTP/1.1
|
|
- Core-\>core
|
|
}
|
|
|
|
(StatusCodeException (Response {responseStatus = Status {statusCode = 403, statusMessage = "Forbidden"}, responseVersion = HTTP/1.1, responseHeaders = [("Date","Sun, 10 Mar 2019 06:58:06 GMT"),("Server","Apache/2.2.22 (Debian)"),("Strict-Transport-Security","max-age=63072000; includeSubDomains"),("Vary","Accept-Encoding"),("Content-Encoding","gzip"),("Content-Length","256"),("Content-Type","text/html; charset=iso-8859-1")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}) "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>403 Forbidden</title>\n</head><body>\n<h1>Forbidden</h1>\n<p>You don't have permission to access /trac/ghc/wiki/Commentary/Compiler\non this server.</p>\n<hr>\n<address>Apache/2.2.22 (Debian) Server at ghc.haskell.org Port 443</address>\n</body></html>\n"))
|
|
- [Strictness analysis](commentary/compiler/strictness-analysis)
|
|
|
|
- Core-\>CorePrep
|
|
Original source:
|
|
- CorePrep-\>Stg?
|
|
|
|
- [The code generator](commentary/compiler/code-gen): Stg-\>Cmm
|
|
```trac
|
|
|
|
|
|
- [The GHC API](commentary/compiler/api)
|
|
|
|
- [Symbol names and the Z-encoding](commentary/compiler/symbol-names)
|
|
= GHC Commentary: The Compiler =
|
|
- Template Haskell?
|
|
|
|
- [Wired-in and known-key things](commentary/compiler/wired-in)
|
|
The compiler itself is written entirely in Haskell, and lives in the many sub-directories of the [[GhcFile(compiler)]] directory. Here is a block diagram of its top-level structure:
|
|
- [Packages](commentary/compiler/packages)
|
|
|
|
- The Finder?
|
|
[[Image(ghc-top.png)]]
|
|
- [Backends](commentary/compiler/backends):
|
|
|
|
|
|
== Contents ==
|
|
- [C code generator](commentary/compiler/backends/ppr-c)
|
|
|
|
- [Native code generator](commentary/compiler/backends/ncg)
|
|
* [wiki:ModuleDependencies Compiler Module Dependencies] (deals with the arcane mutual recursions among GHC's many data types)
|
|
|
|
* [wiki:Commentary/CodingStyle Coding guidelines]
|
|
## Overall Structure
|
|
[[BR]][[BR]]
|
|
|
|
* [wiki:Commentary/Compiler/HscMain Compiling one module: HscMain]
|
|
|
|
* [wiki:Commentary/Compiler/KeyDataTypes Key data types]
|
|
Here is a block diagram of its top-level structure:
|
|
* Passes:
|
|
|
|
* [wiki:Commentary/Compiler/Renamer Renamer]
|
|
[](/trac/ghc/attachment/wiki/Commentary/Compiler/ghc-top.png)
|
|
* Typechecker
|
|
|
|
* Desugarer
|
|
|
|
* Core->core
|
|
The part called **HscMain** deals with compiling a single module. On top of this is built the **compilation manager** (in blue) that manages the compilation of multiple modules. It exports an interface called the **GHC API**. On top of this API are four small front ends:
|
|
* [wiki:Commentary/Compiler/StrictnessAnalysis Strictness analysis]
|
|
|
|
* Core->CorePrep
|
|
- GHCi, the interactive environment, is implemented in [compiler/ghci/InteractiveUI.hs](/trac/ghc/browser/ghc/compiler/ghci/InteractiveUI.hs) and sits squarely on top of the GHC
|
|
* [wiki:Commentary/Compiler/Core2Stg CorePrep->Stg]
|
|
API.
|
|
* [wiki:Commentary/Compiler/CodeGen The code generator]: Stg->Cmm
|
|
|
|
[[BR]][[BR]]
|
|
- `--make` is almost a trivial client of the GHC API, and is implemented in [compiler/main/Main.hs](/trac/ghc/browser/ghc/compiler/main/Main.hs).
|
|
* [wiki:Commentary/Compiler/API The GHC API]
|
|
|
|
* [wiki:Commentary/Compiler/SymbolNames Symbol names and the Z-encoding]
|
|
- `-M`, the Makefile dependency generator, is also a client of the GHC API and is implemented in
|
|
* [wiki:Commentary/Compiler/TemplateHaskell Template Haskell]
|
|
[compiler/main/DriverMkDepend.hs](/trac/ghc/browser/ghc/compiler/main/DriverMkDepend.hs).
|
|
* [wiki:Commentary/Compiler/WiredIn Wired-in and known-key things]
|
|
|
|
* [wiki:Commentary/Compiler/Packages Packages]
|
|
- The "one-shot" mode, where GHC compiles each file on the command line separately (eg. `ghc -c Foo.hs`). This mode bypasses teh GHC API, and is implemented
|
|
* [wiki:Commentary/Compiler/Finder The Finder]
|
|
directly on top of [HscMain](commentary/compiler/hsc-main), since it compiles only one file at a time. In fact, this is all that
|
|
* [wiki:Commentary/Compiler/Backends Backends]:
|
|
GHC consisted of prior to version 5.00 when GHCi and `--make` were introduced.
|
|
* [wiki:Commentary/Compiler/Backends/PprC C code generator]
|
|
|
|
* [wiki:Commentary/Compiler/Backends/NCG Native code generator]
|
|
|
|
|
|
GHC is packaged as a single binary in which all of these front-ends are present, selected by the command-line flags indicated above. There is a single command-line interface implemented in [compiler/main/Main.hs](/trac/ghc/browser/ghc/compiler/main/Main.hs).
|
|
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
|
|
In adition, GHC is compiled, without its front ends, as a *library* which can be imported by any Haskell program; see [the GHC API](commentary/compiler/api). |
|
directly on top of [wiki:Commentary/Compiler/HscMain 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 [[GhcFile(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 [[GhcFile(compiler/main/Main.hs)]].
|
|
|
|
|
|
|
|
* {{{-M}}}, the Makefile dependency generator, is also a client of the GHC API and is implemented in
|
|
|
|
[[GhcFile(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 [[GhcFile(compiler/main/Main.hs)]].
|
|
|
|
|
|
|
|
``` |
|
|