From 1ac88fb8349ae9f9078793ddf105a62b7eb9c9cc Mon Sep 17 00:00:00 2001 From: samvher Date: Sat, 8 Aug 2015 11:09:42 +0200 Subject: [PATCH] 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. --- 000_introduction.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/000_introduction.md b/000_introduction.md index d65e6e3..7b7372b 100644 --- a/000_introduction.md +++ b/000_introduction.md @@ -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: