|
CONVERSION ERROR
|
|
# GHC Commentary: The Code Generator
|
|
|
|
|
|
Error: HttpError (HttpExceptionRequest Request {
|
|
[compiler/codeGen](/trac/ghc/browser/ghc/compiler/codeGen)
|
|
host = "ghc.haskell.org"
|
|
|
|
port = 443
|
|
## Storage manager representations
|
|
secure = True
|
|
|
|
requestHeaders = []
|
|
|
|
path = "/trac/ghc/wiki/Commentary/Compiler/CodeGen"
|
|
The code generator needs to know the layout of heap objects, because it generates code that accesses and constructs those heap objects. The runtime also needs to know about the layout of heap objects, because it contains the garbage collector. How can we share the definition of storage layout such that the code generator and the runtime both have access to it, and so that we don't have to keep two independent definitions in sync?
|
|
queryString = "?version=3"
|
|
|
|
method = "GET"
|
|
|
|
proxy = Nothing
|
|
Currently we solve the problem this way:
|
|
rawBody = False
|
|
|
|
redirectCount = 10
|
|
- C types representing heap objects are defined in the C header files, see for example [includes/Closures.h](/trac/ghc/browser/ghc/includes/Closures.h).
|
|
responseTimeout = ResponseTimeoutDefault
|
|
|
|
requestVersion = HTTP/1.1
|
|
- A C program, [includes/mkDerivedConstants.c](/trac/ghc/browser/ghc/includes/mkDerivedConstants.c), `#includes` the runtime headers.
|
|
}
|
|
This program is built and run when you type `make` or `make boot` in `includes/`. It is
|
|
(StatusCodeException (Response {responseStatus = Status {statusCode = 403, statusMessage = "Forbidden"}, responseVersion = HTTP/1.1, responseHeaders = [("Date","Sun, 10 Mar 2019 07:03:39 GMT"),("Server","Apache/2.2.22 (Debian)"),("Strict-Transport-Security","max-age=63072000; includeSubDomains"),("Vary","Accept-Encoding"),("Content-Encoding","gzip"),("Content-Length","261"),("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/CodeGen\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"))
|
|
run twice: once to generate `includes\DerivedConstants.h`, and again to generate
|
|
|
|
`includes/GHCConstants.h`.
|
|
Original source:
|
|
|
|
|
|
- The file `DerivedConstants.h` contains lots of `#defines` like this:
|
|
```trac
|
|
|
|
|
|
```wiki
|
|
|
|
#define OFFSET_StgTSO_why_blocked 18
|
|
= GHC Commentary: The Code Generator =
|
|
```
|
|
|
|
|
|
[[GhcFile(compiler/codeGen)]]
|
|
which says that the offset to the why_blocked field of an `StgTSO` is 18 bytes. This file
|
|
|
|
is `#included` into [includes/Cmm.h](/trac/ghc/browser/ghc/includes/Cmm.h), so these offests are available to the
|
|
== Storage manager representations ==
|
|
[hand-written .cmm files](commentary/rts/cmm).
|
|
|
|
|
|
The code generator needs to know the layout of heap objects, because it generates code that accesses and constructs those heap objects. The runtime also needs to know about the layout of heap objects, because it contains the garbage collector. How can we share the definition of storage layout such that the code generator and the runtime both have access to it, and so that we don't have to keep two independent definitions in sync?
|
|
- The file `GHCConstants.h` contains similar definitions:
|
|
|
|
|
|
Currently we solve the problem this way:
|
|
```wiki
|
|
|
|
oFFSET_StgTSO_why_blocked = 18::Int
|
|
* C types representing heap objects are defined in the C header files, see for example [[GhcFile(includes/Closures.h)]].
|
|
```
|
|
|
|
|
|
* A C program, [[GhcFile(includes/mkDerivedConstants.c)]], `#includes` the runtime headers.
|
|
This time the definitions are in Haskell syntax, and this file is `#included` directly into
|
|
This program is built and run when you type `make` or `make boot` in `includes/`. It is
|
|
[compiler/main/Constants.lhs](/trac/ghc/browser/ghc/compiler/main/Constants.lhs). This is the way that these offsets are made
|
|
run twice: once to generate `includes\DerivedConstants.h`, and again to generate
|
|
available to GHC's code generator.
|
|
`includes/GHCConstants.h`.
|
|
|
|
|
|
## Generated Cmm Naming Convention
|
|
* The file `DerivedConstants.h` contains lots of `#defines` like this:
|
|
|
|
{{{
|
|
|
|
#define OFFSET_StgTSO_why_blocked 18
|
|
See [compiler/cmm/CLabel.hs](/trac/ghc/browser/ghc/compiler/cmm/CLabel.hs)
|
|
}}}
|
|
|
|
which says that the offset to the why_blocked field of an `StgTSO` is 18 bytes. This file
|
|
|
|
is `#included` into [[GhcFile(includes/Cmm.h)]], so these offests are available to the
|
|
Labels generated by the code generator are of the form `<name>_<type>`
|
|
[wiki:Commentary/Rts/Cmm hand-written .cmm files].
|
|
where `<name>` is `<Module>_<name>` for external names and `<unique>` for
|
|
|
|
internal names. `<type>` is one of the following:
|
|
* The file `GHCConstants.h` contains similar definitions:
|
|
|
|
{{{
|
|
<table><tr><th>info</th>
|
|
oFFSET_StgTSO_why_blocked = 18::Int
|
|
<td>Info table
|
|
}}}
|
|
</td></tr>
|
|
This time the definitions are in Haskell syntax, and this file is `#included` directly into
|
|
<tr><th>srt</th>
|
|
[[GhcFile(compiler/main/Constants.lhs)]]. This is the way that these offsets are made
|
|
<td>Static reference table
|
|
available to GHC's code generator.
|
|
</td></tr>
|
|
|
|
<tr><th>srtd</th>
|
|
== Generated Cmm Naming Convention==
|
|
<td>Static reference table descriptor
|
|
|
|
</td></tr>
|
|
See [[GhcFile(compiler/cmm/CLabel.hs)]]
|
|
<tr><th>entry</th>
|
|
|
|
<td>Entry code (function, closure)
|
|
Labels generated by the code generator are of the form {{{<name>_<type>}}}
|
|
</td></tr>
|
|
where {{{<name>}}} is {{{<Module>_<name>}}} for external names and {{{<unique>}}} for
|
|
<tr><th>slow</th>
|
|
internal names. {{{<type>}}} is one of the following:
|
|
<td>Slow entry code (if any)
|
|
|
|
</td></tr>
|
|
info:: Info table
|
|
<tr><th>ret</th>
|
|
srt:: Static reference table
|
|
<td>Direct return address
|
|
srtd:: Static reference table descriptor
|
|
</td></tr>
|
|
entry:: Entry code (function, closure)
|
|
<tr><th>vtbl</th>
|
|
slow:: Slow entry code (if any)
|
|
<td>Vector table
|
|
ret:: Direct return address
|
|
</td></tr>
|
|
vtbl:: Vector table
|
|
<tr><th>\<n\>_alt</th>
|
|
<n>_alt:: Case alternative (tag n)
|
|
<td>Case alternative (tag n)
|
|
dflt:: Default case alternative
|
|
</td></tr>
|
|
btm:: Large bitmap vector
|
|
<tr><th>dflt</th>
|
|
closure:: Static closure
|
|
<td>Default case alternative
|
|
con_entry:: Dynamic Constructor entry code
|
|
</td></tr>
|
|
con_info:: Dynamic Constructor info table
|
|
<tr><th>btm</th>
|
|
static_entry:: Static Constructor entry code
|
|
<td>Large bitmap vector
|
|
static_info:: Static Constructor info table
|
|
</td></tr>
|
|
sel_info:: Selector info table
|
|
<tr><th>closure</th>
|
|
sel_entry:: Selector entry code
|
|
<td>Static closure
|
|
cc:: Cost centre
|
|
</td></tr>
|
|
ccs:: Cost centre stack
|
|
<tr><th>con_entry</th>
|
|
|
|
<td>Dynamic Constructor entry code
|
|
Many of these distinctions are only for documentation reasons. For
|
|
</td></tr>
|
|
example, _ret is only distinguished from _entry to make it easy to
|
|
<tr><th>con_info</th>
|
|
tell whether a code fragment is a return point or a closure/function
|
|
<td>Dynamic Constructor info table
|
|
entry.
|
|
</td></tr>
|
|
|
|
<tr><th>static_entry</th>
|
|
``` |
|
<td>Static Constructor entry code
|
|
|
|
</td></tr>
|
|
|
|
<tr><th>static_info</th>
|
|
|
|
<td>Static Constructor info table
|
|
|
|
</td></tr>
|
|
|
|
<tr><th>sel_info</th>
|
|
|
|
<td>Selector info table
|
|
|
|
</td></tr>
|
|
|
|
<tr><th>sel_entry</th>
|
|
|
|
<td>Selector entry code
|
|
|
|
</td></tr>
|
|
|
|
<tr><th>cc</th>
|
|
|
|
<td>Cost centre
|
|
|
|
</td></tr>
|
|
|
|
<tr><th>ccs</th>
|
|
|
|
<td>Cost centre stack
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
|
|
|
|
Many of these distinctions are only for documentation reasons. For
|
|
|
|
example, _ret is only distinguished from _entry to make it easy to
|
|
|
|
tell whether a code fragment is a return point or a closure/function
|
|
|
|
entry. |