[LLVMdev] LLVM Newb: Getting started

Reid Spencer rspencer at reidspencer.com
Sat Nov 25 09:41:14 PST 2006


On Sat, 2006-11-25 at 12:24 +0100, Wolfgang Draxinger wrote:
> Am Freitag, 24. November 2006 03:00 schrieb Reid Spencer:
> 
> > If you're making your own front end, you probably won't need it :)
> 
> Well, I wanted to play around with it, so see, how my older programs 
> perform with it.
> 
> So far I managed to get some programs running by folowing scheme:
> 
> for src in $infiles; do
> llvm-gcc -o $src.bc -c $src ;
> opt -f -o $src.bc.opt $src.bc ;
> llc -f $src.bc.opt ;
> gcc -c $src.bc.opt.s ;
> done
> 
> gcc -o $name *.o

If you're using llvm-gcc4, you can reduce this to:

llvm-gcc -O2 $infiles -o $name

> 
> However until now I always had to compile the source file with the 
> main function directly with gcc, so that the __main function (to 
> initialize the globals and static constructors) gets created. 
> 
> I did not manage to make llvm-gcc create __main.

I think Anton already answered this.

> 
> > If you can create platform independent code from D, then you should
> > be able to just use the LLVM bytecode representation.
> 
> D itself is platform independent, but since D is also aimed at system 
> programming it has an inline asembler. However one can supply 
> different kinds of assembler through conditional comilation, so the 
> following would be completely valid:
> 
> void foo(){
>     version(x86) {
>         asm {
> /* x86 assembler */
>         }
>     } else version(llvm) {
>         asm {
> /* llvm assembler */
>         }
>     } else {
> /* plain D implementation */
>     }
> }
> 
> <http://www.digitalmars.com/d/iasm.html>
> <http://www.digitalmars.com/d/version.html>
> 
> Any ideas, how this could be integrated with LLVM? 

As John mentioned, you should probably just use LLVM's inline assembly
capability. It is already being used to compile the inline assembly in
the Linux kernel and the C library. While inline assembly capability is
not fully complete, it is sufficient for most uses. Please see these
documents:
http://llvm.org/docs/LangRef.html#moduleasm
http://llvm.org/docs/LangRef.html#inlineasm
http://llvm.org/doxygen/classllvm_1_1InlineAsm.html 


> The IMHO most naive 
> approach would be to add labels where the asm begins and ends. Then 
> the plattform dependent assembler being parted from the code llvm 
> gets to see and being processed by an external assembler into object 
> code. Later in the process the linker then reinserts the assembler 
> object code.

Most naive approach is to use the LLVM support for this :)

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