Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Write Your Own Compiler with LLVM

252 views
Skip to first unread message

A.F.

unread,
Feb 9, 2010, 10:56:03 PM2/9/10
to
Hi,

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
http://llvm.org/ProjectsWithLLVM/#compilerwrite

But more focused and a little more advanced.

And by the way, my goal is to use the LLVM.

Thanks.
Best Regards.

A.F.

Stephen Horne

unread,
Feb 10, 2010, 1:33:25 PM2/10/10
to

I found the Kaleidoscope tutorial to be easier...

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

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.

http://llvm.org/docs/LangRef.html

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...

http://stackoverflow.com/questions/2129263/how-to-build-llvm-using-gcc-4-on-windows

Jon Harrop

unread,
Feb 10, 2010, 8:43:51 PM2/10/10
to
A.F. wrote:
> Hi,
>
> 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
> http://llvm.org/ProjectsWithLLVM/#compilerwrite
>
> But more focused and a little more advanced.

You may like the HLVM series I wrote for the OCaml Journal that describes
the design and implementation of a high-level virtual machine with tuples,
discriminated unions, a FFI, JIT compilation and a multicore-friendly
garbage collector:

http://ocamlnews.blogspot.com/2009/01/building-virtual-machine-using-llvm.html
http://ocamlnews.blogspot.com/2009/02/building-virtual-machine-using-llvm.html
http://ocamlnews.blogspot.com/2009/03/building-virtual-machine-with-llvm-part.html
http://ocamlnews.blogspot.com/2009/10/llvm-26-support-and-new-hlvm-garbage.html
http://ocamlnews.blogspot.com/2010/01/high-performance-parallel-programming.html

There is also a full compiler series in progress:

http://ocamlnews.blogspot.com/2009/06/compiler-development-part-1.html

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u

0 new messages