mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-09-11 11:46:57 +03:00
Some edits in "Code generation" section
The role of the first few snippets is not completely clear from the text, I think it would be good to give some more context.
This commit is contained in:
parent
9c57331bc1
commit
1ac88fb834
@ -368,18 +368,20 @@ evaluation explicit directly in the AST.
|
||||
Code Generation
|
||||
---------------
|
||||
|
||||
From the core language we will either evaluate it on top of a high-level
|
||||
interpreter written in Haskell itself, or into another intermediate language
|
||||
like C or LLVM which can itself be compiled into native code.
|
||||
After translating an expression to the core language we will either evaluate
|
||||
it with a high-level interpreter written in Haskell itself, or translate it
|
||||
to another intermediate language (such as LLVM IR or GHC's Cmm) which can be
|
||||
compiled into native code. This intermediate language abstracts over the
|
||||
process of assigning values to, and moving values between CPU registers and
|
||||
main memory.
|
||||
|
||||
As an example, the statement
|
||||
|
||||
```haskell
|
||||
let f x = x + 1
|
||||
```
|
||||
|
||||
Quite often this process will involve another intermediate representation which
|
||||
abstracts over the process of assigning and moving values between CPU registers
|
||||
and main memory. LLVM and GHC's Cmm are two target languages serving this
|
||||
purpose.
|
||||
which corresponds to the following assembly instructions:
|
||||
|
||||
```haskell
|
||||
f:
|
||||
@ -388,6 +390,8 @@ f:
|
||||
ret
|
||||
```
|
||||
|
||||
looks like this in LLVM IR (note the absence of mov instructions):
|
||||
|
||||
```haskell
|
||||
define i32 @f(i32 %x) {
|
||||
entry:
|
||||
@ -396,9 +400,9 @@ entry:
|
||||
}
|
||||
```
|
||||
|
||||
From here the target language can be compiled into the system's assembly
|
||||
language. All code that is required for evaluation is *linked* into the
|
||||
resulting module.
|
||||
From the intermediate representation the code can be compiled into the
|
||||
system's assembly language. Any additional code that is required for
|
||||
evaluation is *linked* into the resulting module.
|
||||
|
||||
```perl
|
||||
f:
|
||||
|
Loading…
Reference in New Issue
Block a user