Source-to-source compiler

From Wikipedia, the free encyclopedia

Jump to: navigation, search

A "source-to-source compiler" is a type of compiler that takes a high level language as its input and outputs a high level language. For example, an automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g. OpenMP) or language constructs (e.g. Fortran's DOALL statements).

Another purpose of source-to-source-compiling is translating legacy code to use the next version of the underlying programming language or an API that breaks backwards compatibility. Examples of this are seen in Python 3000 or Qt's qt3to4 tool.

LLVM can translate from any Language supported by gcc 4.2.1 ( c, ada, c++, fortran, objc, obj-c++, or java ) to any of: "C", "C++", or "MSIL" by way of the "arch" command in llvm-gcc .

EG:
% llvm-g++ x.cpp -o program
% llc -march=c program.bc -o program.c
% cc x.c

% llvm-g++ x.cpp -o program
% llc -march=msil program.bc -o program.msil

The "arch" command can also emit assembly Language code in these architectures:

x86 -> 32-bit X86: Pentium-Pro and above
x86-64 -> 64-bit X86: EM64T and AMD64
sparc -> SPARC
ppc32 -> PowerPC 32
ppc64 -> PowerPC 64
alpha -> Alpha [experimental]
ia64 -> IA-64 (Itanium) [experimental]
arm -> ARM
thumb -> Thumb
mips -> Mips
mipsel -> Mipsel
cellspu -> STI CBEA Cell SPU [experimental]
pic16 -> PIC16 14-bit [experimental].
cooper -> PIC16 Cooper [experimental].
xcore -> XCore

[edit] See also

[edit] References