Changes between Version 6 and Version 7 of Commentary/Rts/Cmm


Ignore:
Timestamp:
May 4, 2014 6:51:41 PM (13 months ago)
Author:
Tarrasch
Comment:

Add lots of reading resources

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/Cmm

    v6 v7  
    77We use the C preprocessor on `.cmm` files, making extensive use of macros to make writing this low-level code a bit less tedious and error-prone.  Most of our C-- macros are in [[GhcFile(includes/Cmm.h)]]. One useful fact about the macros is `P_` is an alias for `gcptr`, and you should not use it for non-garbage-collected pointers. 
    88 
    9 For more information on Cmm (GHC's implementation of C--), see [wiki:Commentary/Compiler/CmmType the Cmm language] page. 
     9 
     10== Reading references == 
     11 
     12Reading material for learning Cmm is somewhat scattered, so I (Arash) have created a list of useful links. Since the Cmm language is changing as GHC changes, I have prioritized. (''Feel free to add/remove/modify this this list! :)'') 
     13 
     14 
     15 * An overview of Cmm is given in [https://davidterei.com/downloads/papers/terei:2009:honours_thesis.pdf David Terei's bachelor thesis] (chapter 2.4.3). 
     16 * The comments in the beginning of [[GhcFile(compiler/cmm/CmmParse.y)]] is super-useful and kept up to date. The rest of the file contains the ''grammar'' of the language. Afraid of grammars? Edward Yang wrote this fantastic [http://blog.ezyang.com/2013/07/no-grammar-no-problem/ blog post] on how to understand the constructs of Cmm by using the grammar.   
     17 * Cmm has a preprocessor like the one in C and many of the macros are defined in [[GhcFile(includes/Cmm.h)]].  
     18 * In 2012, Simon Marlow extended the Cmm language by adding a new high-level syntax which can be used when you don't need low-level access (like registers). The [https://github.com/ghc/ghc/commit/a7c0387d20c1c9994d1100b14fbb8fb4e28a259e commit] explains the details. 
     19 * Cmm is also described [wiki:Commentary/Compiler/CmmType on this wiki], but it is written before the new syntax was introduced. 
     20 * Stack frame types are created using ``INFO_TABLE_RET``, the syntax can be confusing since there are both ''arguments'' and ''fields'', I (Arash) have not seen anything like it in other programming languages. I tried to explain it in my [http://arashrouhani.com/papers/master-thesis.pdf master thesis] (sections 4.2 and 4.2.1). 
     21 
     22== Other information == 
     23 
     24It can take time to learn Cmm. One unintuitive thing to watch out for is that there are no function calls in low-level cmm code. The new syntax from 2012 allows function calls but you should know that they are kind of magical. 
     25 
     26We say that '''Cmm''' is GHC's implementation of '''C--'''. This naming scheme is not done consistently everywhere, unfortunately. If you are interested in C-- (which have diverged from Cmm), you can check out the [http://www.cminusminus.org/ website] and the [http://www.cs.tufts.edu/~nr/c--/extern/man2.pdf specification].