[LLVMdev] 'Implementing a language with LLVM' tutorial

Chris Lattner sabre at nondot.org
Mon Nov 5 11:42:40 PST 2007

On Mon, 5 Nov 2007, Vikram S. Adve wrote:
> -- It would be helpful to add some navigation links at the top and bottom of 
> the pages.

I added a TOC to each chapter, thanks.

> -- Not clear why PrototypeAST::Codegen returns a Function* instead of a 
> Value* like the other CodeGen methods?

I clarified this in the text.  The short version is that PrototypeAST 
doesn't correspond to an expression value.

> -- It can be convenient to use Visitor methods on the AST classes for code 
> generation, instead of hard-coding the CodeGen methods into the AST classes. 
> Many languages will need other traversals besides the CodeGen operations, 
> e.g., for type checking, class layout, etc.

Yep, the tutorial also leaks memory, uses global variables, and commits a 
number of other sins against good software engineering practice.  However, 
I added a mention of the possibility of using a visitor to the text.

> -- In the optimization section, how much code size reduction have you seen in 
> practice by doing constant folding in the LLVMFoldingBuilder (instead of just 
> letting the later optimization pass take care of it)?

Depends on the language.  For C, it can be significant.  In any case, 
there is no reason not to use the folding builder, so it doesn't hurt 

> -- One of the harder parts is generating type declarations correctly for 
> recursively connected types (e.g., for classes).  Without extending 
> Kaleidoscope, it would be be helpful to add a link to the Programmers Manual 
> section on recursive type construction.

I added a link to chapter 8, thanks for the feedback!


> On Nov 5, 2007, at 1:14 AM, Chris Lattner wrote:
>>  Hi All,
>>  LLVM has long needed a tutorial for people who are interested in using
>>  it to implement their favorite language and to demonstrate how to use
>>  the JIT.  To help solve this, I've put together a little tutorial that
>>  runs through the implementation and extension of a toy language here:
>>     http://llvm.org/docs/tutorial/
>>  At this point, the tutorial is feature complete, but might still need
>>  some final editing.  Before I try to get other sites to link to it, I
>>  thought it would be good to get some more eyeballs on it and get some
>>  thoughts and feedback from you.
>>  Anyone have thoughts or feedback? :)
>>  -Chris
>>  _______________________________________________
>>  LLVM Developers mailing list
>>  LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>  http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



More information about the llvm-dev mailing list