Building a compiler
(considering characteristics of embedded processors)
Peter Marwedel
University of Dortmund, Germany
P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006
Fri2 - 1 -
Universität Dortmund
Effort for building a compiler
So far we assumed that all the optimizations can be added to some existing tool chain.
Sometimes, a custom compiler is required, but: the effort for building a custom compiler is underestimated.
It is not sufficient to design a processor and then think about the compiler later.
Try to avoid the design of a full compiler. Approaches:
- Modify an existing compiler.
- Implement proposed optimizations as pre- or postpass optimization.
- Use existing standard software components
- Use retargetable compiler (see below)
What if we have to look at the entire compiler ?
P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006
Fri2 - 2 -
Universität Dortmund
Anatomy of a compiler
Compiler
C-source
frontend
HL-IR
HL2LL
LL-IR
backend
optimizations
ASM
assembler
OBJ
linker
EXE
Do not start from scratch!
P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006
Fri2 - 3 -
Universität Dortmund
Existing Compiler Frameworks: gcc
GNU Compiler Collection (GNU public license)
Family of C & C++ compilers
(also supports Java and Fortran)
Available for many different architectures
(e.g. Sparc, Mips, Alpha)
Code-transformation into an IR (Intermediate
Representation) called RTL (Register Transfer
Language)
Designed for homogeneous register machines
No ideal fit for embedded processors based on slide by
(heterogeneous registers etc.)
Désirée Kraus, Inf 12, 2005
P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006
Fri2 - 4 -
Universität Dortmund
Existing Compiler Frameworks: lcc
Little C Compiler (Princeton University)
„lightweight compiler“ (~ 13.000 lines of code)
„A retargetable C