views:

644

answers:

3

I'm bootstrapping a programming language compiler on top of LLVM. Currently I'm mostly done writing a compiler for a subset of C which is self-compiling. When I'm finished with that, I'll bootstrap my language away from C, maintaining self-compilation as I go.

Since the compiler is self-compiling, any features of C that I use I will have to implement. So it's a constant balance: if I use too many features I will have to implement more than I want to, but if I don't implement enough features it will be difficult to write code.

One such feature is the LLVM bindings. Generating LLVM intermediate representation without the LLVM C bindings is difficult. However, if I us the LLVM bindings, I have to implement them again when I branch away from C.

I'm having some difficulty here, so I a looking for alternative solutions. Any ideas?

+7  A: 

You could use the LLVM C bindings, but that requires your language understand enough C to do that.

Another alternative is to write out LLVM assembly language (a text file) and use llvm-as to turn that into bitcode.


Edit:

I re-read you question, I think you already understand the llvm-as vs. binding stuff.

Your language will probably want to be able to bind to C anyway for support libraries, etc. Use the C bindings for now and write your own bindings when you get further along.

Richard Pennington
I hadn't considered that the C bindings could be a *temporary* solution. Good idea.
Imagist
A: 

At some point, you're probably going to want to provide an API for wrapping C libraries as extension modules. LLVM may already support this (I know the parrot vm does). Why not use whatever extension system you use to wrap LLVM's own API? They may already support that, too. :)

+1  A: 

A Strategy for using ANTLR + StringTemplate + LLVM

HTH

plan9assembler
I love ANTLR and StringTemplate!
fuzzy lollipop