Re: How to Write Your Own Compiler with LLVM

Stephen Horne <>
Wed, 10 Feb 2010 18:33:25 +0000

          From comp.compilers

Related articles
How to Write Your Own Compiler with LLVM (A.F.) (2010-02-09)
Re: How to Write Your Own Compiler with LLVM (Stephen Horne) (2010-02-10)
Re: How to Write Your Own Compiler with LLVM (Jon Harrop) (2010-02-11)
| List of all articles for this month |

From: Stephen Horne <>
Newsgroups: comp.compilers
Date: Wed, 10 Feb 2010 18:33:25 +0000
References: 10-02-040
Keywords: LLVM, tools
Posted-Date: 10 Feb 2010 15:53:48 EST

On Tue, 9 Feb 2010 19:56:03 -0800 (PST), "A.F."
<> wrote:

> So sorry if the question seems basic, but would like an paper or
>another document equivalent to the tutorial below:
>How to Write Your Own Compiler
> But more focused and a little more advanced.
> And by the way, my goal is to use the LLVM.

I found the Kaleidoscope tutorial to be easier...

You can probably skip chapters 1 and 2 if you're OK with scanning,
parsing and AST handling. LLVM itself is only introduced in chapter 3.

Once you complete the tutorial, I recommend the LLVM assembler
programmers reference.

Transferring the ideas from this form to LLVM library calls (e.g.
builder calls to generate particular instructions) is fairly easy. The
important thing is to understand how LLVM intermediate code works. If
you've used a non-virtual assembler before, probably the biggest
surprise is the phi instruction needed for SSA, and this is explained
in the Kaleidoscope tutorial.

The Doxygen documentation for the library isn't too bad, but you do
need to have some idea where to look before you dive in. Good starting
points are the main classes mentioned in the Kaleidoscope tutorial.

Also, it may be better to build the Doxygen with GraphViz *not*
installed. The diagrams it generates tend to be far too large to be
useful on screen, no matter how big your monitor, and you'd need a
large wall to display even a selection of them as posters.

One of the biggest challenges with LLVM, if you're running Windows,
may be getting the thing to build - though on Linux (and with some
compilers, on Windows) this is very easy. If you're building using
MinGW GCC 4.4.0, for instance, look here...

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.