Hacker News new | past | comments | ask | show | jobs | submit login
LLVM Tutorial (llvm.org)
328 points by thewarrior on Feb 1, 2013 | hide | past | favorite | 32 comments



Surprising that this topic has (as of now) 60 point and only two comments.

At Taodyne, we use LLVM as the foundation for our 3D dynamic document description language. This makes it possible to do interesting things in real-time, see e.g. http://www.taodyne.com/shop/en/blog/58-live-coding-creating-.... LLVM is pretty powerful, and now relatively stable as far as even the C++ API is concerned. In earlier days, having the C++ API change underneath you in significant way at every release was a real pain.

That being said, I was not a real fan of their documentation in general, and the Kaleidoscope tutorial was no exception. But it looks like they are putting a lot of effort into this, and it looks much much better than it used to.


HN is one of those great communities where people usually don't comment when they they aren't qualified to comment. It's either that, or they get down voted to heck and hell banned if they continuously post low quality material.

It's probably more of the latter :)

The one problem I have with HN is the basic/extreme bike-shedding situation we have here.

Articles on hiring, firing, culture, etc. (softer - more bs subjects) and the singularity, complex economics and quantum physics (softer - more bs subjects for laymen) seem to get a metric ton of crappy comments from people who aren't qualified to talk about said topics and HNers seem to be much too nice (or don't care) enough to point out the crap for what it is.

I try to avoid those types of posts nowadays.


[dead]


Bitch please.

If you want to insult me for no particular reason - at least have the balls to swear at me with your real account.

Trollers gonna troll.


I believe that it has no comments because this tutorial is around for years and almost everyone who knows LLVM have already read it.


The OCaml version of the same tutorial is so much nicer http://llvm.org/docs/tutorial/OCamlLangImpl1.html


Are there any books or resources that teach how you would go about using flex, bison and llvm together to create something more substantial. I would find this incredibly useful.


You can check my WIP language for an example. The following is the repository where every component (lexer, parser, compiler, running-time library) is in its own module.

https://github.com/castel/libcastel

According to my experience on this language, I would recommand you ragel and lemon over flex and bison. They are very, very easy to bundle into a C++ application, without messing too much with the global symbol namespace.

A nice example is the Castel lexer, which is actually a preprocessed C++ source file : https://github.com/castel/libcastel/blob/master/parse/source...


Thanks for pointing this out. I will definitely check them out.


Making my first toy language is one of the most interesting advertures as a programmer. LLVM is quite complex and the documentation is far from stellar but it's usable for teaching how a compiler works.

Also I like the restyling. LLVM landing page is so 90'.


One thing you might find interesting is to generate some kind of bytecode as textual representation.

Then write Assembly macros that translate those bytecode into real Assembly code.

This will give you a nice picture without much effort how code generation can be done.

Surely the performance won't be stellar, but is a nice experience.

On the other hand you can plug it directly into LLVM, but there you get more things to learn at the same time, which might slow you down.


Looks like it's done with sphinx, which is wonderful for this sort of thing.


Built with HTML tables too!


I would love a tutorial about LLVM that used a decent proper subset of scheme as its tutorial language and not a procedural language. Anyone know any?


There's an OCaml version of the same tutorial...


That's not what I meant. Maybe I was unclear. I mean that instead of the makey-uppy Kaleidoscope procedural langauge a makey-uppy mini scheme was used instead, that is to say KaleidoscopeScheme ...


Of course, pedagogy goes out of the window and we enter the realm of magic once we try to implement continuations.

Scheme without continuations is no different than any other simple Algol. (minus GC, numeric tower, macros, etc. of course)


Thank you, I'd not seen this before.

I have always been interested in compiler design having not been put off it by doing a computer science degree, but, having not done the degree I've also never learned anything about it. This looks like it should help.

Although, I was very confused by the first couple of sentences - the author apologises for their global variables, and not knowing which part of the compiler they're talking about I don't know if they means they're going to implement kaleidoscope without any notion of scope, and just make everything global, or if they're just talking about the parser code. It's quite clear soon after that it's the latter, but it makes it difficult to read the introduction!


LLVM seems to support 64 bit ARM, now, too:

http://www.phoronix.com/scan.php?page=news_item&px=MTI4O...


I do wonder what on earth ARM was doing that was preventing them from including NEON support, though.


LLVM now has NEON support. Was this an issue in the past?


Well, the addition of LLVM support referenced in the Phoronix article had this bit:

"This patch excludes the NEON support also reviewed due to an outbreak of batshit insanity in our legal department. That will be committed soon bringing the changes to precisely what has been approved."

http://comments.gmane.org/gmane.comp.compilers.llvm.cvs/1349...

I'm just wondering what that was about and how serious it was.


Amazing, thank you so much. This is so interesting. I've always wanted to look into building something small.


Uh... I'm not good at C++ :(


There is also OCaml version there:

http://llvm.org/docs/tutorial/OCamlLangImpl1.html



Interesting, I'm read through the tutorial, and took the source, while tweaking it to conform to RPython, then feeding it into PyPy's translator.

What strikes me is that:

- with PyPy everything is implemented natively, i.e without resorting to foreign abstractions: instead of def CodeGen, I'd write def eval (or whatever my native AST evaluation wants), and instead of g_llvm_builder.fadd(left, right), I'd just do the native left+right. This makes it conceptually less of a mind split, and writing stuff like the BF interpreter is just straightforward [0].

- with LLVM, the concepts are nicely abstracted, and the API reasonably pythonic. I know I'm using LLVM but I don't feel like I'm hitting some thin C wrapper. Those concepts are ported and reinvested into other languages with ease: now that I got them by reading the python tutorial, I'm confident I can find my way in another project on another, less known to me language. Also, due to this abstracted common ground, access to functions coming from outside, (possibly other languages) is made easy. With PyPy I'm stuck to what's made available to RPython land.

[0]: http://morepypy.blogspot.fr/2011/04/tutorial-writing-interpr...


Your observations are pretty accurate. I'm fortunate enough to work with the maintainer of llvmpy and he's done some great work in making llvmpy pretty Pythonic. Should also check llvm-cbuilder the EDSL for building up higher level LLVM constructs:

https://github.com/llvmpy/llvmpy/blob/master/README_LLVM_CBU...


Is the site down for everybody else?


llvm.org has been down nearly all day.


OK, here's a question: is this the same version that was around for half a decade, or is it updated to the latest LLVM API etc?


It is constantly updated to the latest LLVM API. Ok, it is not promptly updated, but it is updated.


Je voudrai hacker un compte moviestarplanet




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: