Cross Compiler
Prepared By: Dr. D. P. Singh
Motivation
• It is not always possible to write and build an application on the same
platform.
• For many embedded environments, for example, the reduced
memory space -- often less than 256 MB, maybe even less than 64
MB, both for RAM and for storage -- just is not practical.
• A reasonable C compiler, the associated tools, and the C Library
required won't fit into such a small space.
cntd…
• Cross-compilers can be useful in other situations, too. I once had to work
on a computer with no C compiler installed, and I had no easy way of
obtaining a precompiled binary.
• I did, however, have the necessary source code for the GNU Compiler
Collection (GCC), a C library (newlib), and the binary utilities on a computer
that did have a C compiler.
• With these tools, I was able to build first a cross-compiler and then a native
compiler for the target computer that I could copy across and use directly.
• Cross-compilers can also be handy when you have a slow machine and a
much faster one and want to build in minutes rather than hours or days.
Introduction
• A Cross Compiler is a compiler that runs on one machine and produce
object code for another machine
• The Cross compiler is used to implement the compiler which is
characterized by 3 languages
• Source Language
• Object Language
• The language in which it is written (Implementation language)
Note: if a compiler has been implemented in its own language then this
arrangement is called a bootstrap arrangement
Cross Compiler Representations
• T-Representation
• A compiler written in language H that translates language S into language T
S T
H
• C-Representation
S T
C H
Full Bootstrapping
• A full bootstrap is necessary when we are building a new compiler from
scratch.
• e.g.
• We want to implement a Ada compiler for machine M. We don’t
currently have access to any Ada compiler.
• First, we will write a subset of Ada compiler in C language
Ada_s M c M Ada_s M Ada M Ada_sn M Ada M
CC CM CM CAda_sn CM CM
Ada_s1 M Ada_s M Ada_s1 M
C Ada_s CM CM
…….
cntd…
• T-Representation
Half Bootstrapping
• If we have a compiler for one language on a different machine
Ada M Ada HM Ada M
CAda C HM C HM
Ada M Ada M Ada M
CAda CHM CM
Thank You