[LLVMdev] LLVM Newb: Getting started

Reid Spencer rspencer at reidspencer.com
Thu Nov 23 18:00:31 PST 2006


Hi Wolfgang,

On Thu, 2006-11-23 at 19:47 +0100, Wolfgang Draxinger wrote:
> A few days ago Craig Black made the suggestion in the D newsgroup, 
> that someone creates a D <http://www.digitalmars.com/d/index.html> 
> frontend for LLVM. Never having heard of LLVM in the past, I 
> immediately got captured by its design when I've read the 
> documentation. I was always scared by GCC - a great piece of 
> software, but horribly bad documented, and in it's own way not very 
> KISS.

Welcome to LLVM :)

> Since I'm currently working on a clean ABI draft for D I thought, that 
> implementing a D frontend for LLVM would also be a good test case for 
> my ABI drafts and so I agreed to implement that frontend.

Wonderful!

> Today I've built LLVM from source (however not the GCC frontend yet) 

If you're making your own front end, you probably won't need it :)

> and played a bit with the assembly language, and it brought up the 
> following questions:
> 
> * How can I define parts of the ABI that cover calling conventions?

LLVM supports calling conventions, if that's what you mean. You can even
create your own, but you'd have to implement them in the code
generators.

> 
> * Which is the LLVM way of creating object files?
> From what I've tried out yet, the llvm-ld will generate a executable. 
> llc produces target specific assembly; there is an option to output 
> object files, but this crashes on my system.

llvm-ld should generate an executable, but alas it is an unfinished
piece of work. 
generally what we do is:

llc input.bc -o output.s
gcc output.s -o program

I've been meaning to finish the llvm-ld and llvmc tools for some time
now but other things have consistently gotten in the way.  One of these
days they'll be working.

Note that you should be able to write a "D" configure file for llvmc
that sets up the various stages for compilation of D programs through
linking. Unfortunately, there isn't much good documentation on it and
the file format is not good. There's an open bug to clean this all up,
but it is not, as yet, implemented.

> * Which is the best way to add support for new object file types. One 
> thing that a lot of people in the D community anticipate is the 
> possibility to compile modules into self contained objects, which can 
> be redistributed without additional header files, and be linked 
> either statically or dynamically into the final program. Kinda like 
> Pascal units. This of course requires to put additional information 
> into the created binary.

If you can create platform independent code from D, then you should be
able to just use the LLVM bytecode representation. Most of the tools put
this format out. Note that LLVM bytecode files are only as platform
independent as the language front end used to create them. The bytecode
files can be distributed and then targeted to any of the platforms that
LLVM supports. The bytecode format even retains which libraries it still
needs to link against so you should be able to turn the bytecode into an
executable fairly readily.

>  And I'd like to try, to let the thing to 
> create CLI binaries 
> <http://www.ecma-international.org/publications/standards/Ecma-335.htm>.

Sounds interesting. How much like Microsoft CLR is it? You could
probably create a backend for CLI quite readily. See the "C" Backend
that turns LLVM IR into C99 code. You can see it here:
http://llvm.org/cvsweb/cvsweb.cgi/llvm/lib/Target/CBackend/Writer.cpp?rev=1.282&content-type=text/x-cvsweb-markup 

Writing a backend to support CLI output should be on the same order of
magnitude as that file. Its not particularly difficult due to the
regularity/simplicity of the LLVM IR.

> 
> And last but not least: Which parts of the documentation must I 
> definitely read in the first place to get started to hack LLVM (I'll 
> read all of course, but I'd like to focus right now).

Try this:

http://llvm.org/pubs/2006-04-25-GelatoLLVMIntro.html 
http://llvm.org/docs/GettingStarted.html 
http://llvm.org/docs/LangRef.html 
http://llvm.org/docs/CommandGuide/index.html 
http://llvm.org/docs/ProgrammersManual.html 
http://llvm.org/docs/GetElementPtr.html 
http://llvm.org/docs/FAQ.html 

Reid.

> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list