Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrapping a language on LLVM

Tags:

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?

like image 226
Imagist Avatar asked Jan 05 '10 20:01

Imagist


2 Answers

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.

like image 88
Richard Pennington Avatar answered Oct 06 '22 20:10

Richard Pennington


A Strategy for using ANTLR + StringTemplate + LLVM

HTH

like image 41
plan9assembler Avatar answered Oct 06 '22 20:10

plan9assembler