Page 1 of 1


Posted: 12 Dec 2012, 11:38
by wread
LLVM is a project started by the University of Illinois; originally, llvm stand for Low Level Virtual Machine, but the scope of the project went still deeper and the name LLVM stayed now as brand name.

Its front end, clang is a c-compiler to the byte-code level, that can do things like this:
An Example Using the LLVM Tool Chain

This section gives an example of using LLVM with the Clang front end.
Example with clang

First, create a simple C file, name it ‘hello.c’:

#include <stdio.h>

int main() {
printf("hello world\n");
return 0;

Next, compile the C file into a native executable:

% clang hello.c -o hello


Clang works just like GCC by default. The standard -S and -c arguments work as usual (producing a native .s or .o file, respectively).

Next, compile the C file into a LLVM bitcode file:

% clang -O3 -emit-llvm hello.c -c -o hello.bc

The -emit-llvm option can be used with the -S or -c options to emit an LLVM .ll or .bc file (respectively) for the code. This allows you to use the standard LLVM tools on the bitcode file.

Run the program in both forms. To run the program, use:

% ./hello


% lli hello.bc

The second examples shows how to invoke the LLVM JIT, lli.

Use the llvm-dis utility to take a look at the LLVM assembly code:

% llvm-dis < hello.bc | less

Compile the program to native assembly using the LLC code generator:

% llc hello.bc -o hello.s

Assemble the native assembly language file into a program:

**Solaris:** % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native

**Others:** % gcc hello.s -o hello.native

Execute the native code program:

% ./hello.native

Note that using clang to compile directly to native code (i.e. when the -emit-llvm option is not present) does steps 6/7/8 for you.
Adding DragonEgg gives fully support for all gcc supported languages and substitutes the gcc optimizers with those generated by llvm. Applications compiled with DragonEgg (Fortran, Ada, C, C++, Objective-C, etc.) run faster and safetier when compiled with LLVM.

I am posting the modules for Porteus 32-bits in the corresponding section of this forum, so you can try them.



Posted: 11 Oct 2013, 12:03
by wread
Meanwhile LLVM is by version 3.3; I packaged this new version for Porteus 2.1 that you can download.

The module llvm-3.3 contains clang-3.3, clang-tools-extra-3.3 and compiler-rt-3.3, it is a 4-in-one module...

I tested the usual elementary stuff, native, bytecode and justintime, and it works.