News for hackers. Stuff that matters.
Re:Compiler Design in C by amelius on Saturday November 15, 2014 @10:48AM (#8611869)
Can somebody recommend a book that covers recent techniques implemented in LLVM?
Re:Compiler Design in C by ltta on Saturday November 15, 2014 @11:21AM (#8611964)
Much of the frontend is pretty much the same: parsing, semantic analysis, type checking. LLLVM mostly comes into play when generating the code. Instead of generating assembbler or opcodes directly, you call into LLVM to create data structures that represent low-level code and then a final call to gen machine code or JIT.

There are several versions of the LLVM Kaleidoscope language tutorial where you build a compiler that supports numeric operations, it is often based on Pratt parsers (at least the official C++ version[1]), but there's a C version on github [2].

In my opinion, you could get pretty far by reading the "Compiler design in C" or "Modern compiler implementation in C" up to the point of optimization and then applying the code generation from kaleidoscope tutorials. LLVM takes care of many optimizations.

[1] http://llvm.org/docs/tutorial/LangImpl1.html [2] https://github.com/benbjohnson/llvm-c-kaleidoscope

Re:Compiler Design in C by nickik on Saturday November 15, 2014 @11:55AM (#8612035)
The good intro to compilers is Engineering a Compiler. It focuse more on optimization then most intro books, and its all SSA.

If you want to go all in on SSA optimization, there is a book called Static Single Assignment Book and its written by a hole list of compiler writers. Its not finished but there is still a lot of information.

You can find it here: http://ssabook.gforge.inria.fr/latest/book.pdf

Or you can go with the classic, Advanced Compiler Design & Implementation. See here, http://www.amazon.com/Advanced-Compiler-Design-Implementatio...

All of them will teach you a lot about LLVM.

Re:Compiler Design in C by ltta on Saturday November 15, 2014 @04:41PM (#8612736)
Speaking of SSA and optimizations, I just remembered that Andy Wingo (core contributor to Guile scheme) has a treasure trove of great articles, e.g. a fun intro to SSA [1] or CPS as used in Guile [2]. His blog is totally worth just browsing around.

[1] http://wingolog.org/archives/2011/07/12/static-single-assign...

[2] http://wingolog.org/archives/2014/01/12/a-continuation-passi...

Re:Compiler Design in C by nickik on Sunday November 16, 2014 @05:57PM (#8615851)
Yes. His posts are a great. He is working on a VM and I do to so I follow his work closly.
Re:Compiler Design in C by drivers99 on Saturday November 15, 2014 @09:39PM (#8613308)
Interesting that on page 6 of this book, it talks about the same idea as LLVM (as I understand it):

"There are advantages and disadvantages to an intermediate-language approach to compiler writing[...] Intermediate languages give you flexibility as well. A single lexical-analyzer/parser front end can be used to generate code for several different machines by providing different back ends that translate a common intermediate language to a machine-specific assembly language. Conversely, you can write several front ends that parse several different high-level languages, but which all output the same intermediate language. This way, compilers for several languages can share a single optimizer and back end."