The LLVM Compiler System is being used for all sorts of interesting things these days. It basically provides an extremely modular and easy to use set of open source (BSD-licensed) compiler libraries that can be used to build various applications from. Despite this, many people don’t really understand it, and are scared away by the breadth of the project or by compilers in general. The Kaleidoscope tutorial starts out from scratch and slowly builds up a simple language to show how LLVM can help out with this. We end up with a JIT compiler for a fairly interesting little language with less than 700 lines of code. Of course, this is just the tip of the iceberg, once you start with LLVM, there are all sorts of things you can do.
From all the attention and famous cases of use, I think we’ll see more and more about this one… in fact, even more with mobile computing and desktop computing getting so close these days.
Actually, this reminds me when OpenGL for BeOS was begin implemented and the engineer build a a program to build most of the OpenGL extensions, because there was so many of them, and it ended up usually better than manual coding most of them… Even if some programmers don’t want to admit, solutions like this will become more and more common each day.
I wonder if Vala guys could target this compiler system to their language resulting some improvement…
Vala compiles to C, so its output is already in native machine code.
I’ve been planning on doing something like this for a little while and this tutorial looks like it will be a great help. YAY!
Although I might wait for the C bindings, C++ irritates me.
Very lame tutorial; the author’s proposals do not scale in a real programming language. And he skips perhaps the most important part, i.e. type checking.
This is probably the first example of the unified HLVM and LLVM. http://www.hlvm.org is designed to be a common runtime for most languages including “typeless” languages like Python.
It’s a tutorial on using LLVM to implement a language, not on how to implement languages in general. If you don’t know _anything at all_ about writing a compiler, you need to read the a compilers textbook (or at least the relevant parts of Wikipedia) first.
Stay away from Wikipedia. I mean it.
Dragon Book FTW!
http://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp…
If it’s that bad. Why don’t you improve it?
I modded you up for the general wisdom contained in your retort. However, notice that I’m criticising this horrid trend of nowadays where people believe that reading whatever is written in Wikipedia is enough to grasp a concept, any concept, and base their work on whatever shallow article comes up on WP.
Bottom line is: buy a book. Read a book. If for no other reason than being healthier for your eyes and blood flow. Some WP articles might be very thorough, but they’re no substitute to the proper literature on any non-trivial subject.
(You’d never attempt to fix a modern car engine after reading Wikipedia articles on 4-stroke engines, would you?)
Some WP articles might be very thorough, but they’re no substitute to the proper literature on any non-trivial subject.
Agreed! It’s an encyclopedia, a place to get a quick overview of the topic, enought to know what to look for next.
Have you ever seen any tutorial that describes every aspect of building a real-life implementation of whatever the tutorial subject is?
Tutorials are simply things that point you to the direction of how things are done under a given environment. It won’t give you a step-by-step breakdown on how to write your own operating system, or to build your own your own Gothic cathedral.
The sole purpose of tutorials is to present concepts you’re familiar with on ways that match the environment you’re working with at the moment. If you need to go beyond that, then you need a “For Dummies” book, then there’s a natural progression to books named after the subject, then books named after the subject with an “Advanced Topics” subtitle, then “Subject: the reference manual”, then after half a decade or so “Subject: becoming more productive”, “Subject: a modern approach”, and finally you manage your way around a simple cheat sheet.
See, tutorials are polar opposites of “cheat sheets”.
(and yes, it gives me the creeps when I see newbie Python programmers using cheat sheets and coming up with sloppiest solution ever for a given problem, coated with the shiniest syntactic sugar…)
Edit: I’m past the edit time for my previous message, but I just found the link to Dragon Book, 2nd ed. on Amazon, and I think it’s worth sharing:
http://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/…
Edited 2007-11-07 18:16
No, I have seen tutorials that are small scale but what they show have real value.
If his purpose was only to show LLVM, he would have skipped lexing and parsing and AST and he would have gone straight to how LLVM is used to produce code.
His tutorial can be summarized into the following simple phrases:
step 1: LLVM has a library which contains classes which can be used to represent a program; LLVM knows how to interpret the instances of these classes to assembly code.
step 2: In order to provide optimizations, you tell the compiler engine which optimizations you require and then you call the engine to optimize the objects produced in step 1.
There is also the fine “Modern Compiler Design” book which I recommend :
http://www.wiley.co.uk/wileychi/grune/
Edited 2007-11-08 08:31