building a compiler

Topics: Compiler, Parsing, Compiler optimization Pages: 29 (2613 words) Published: January 25, 2014
Universität Dortmund

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 Compiler: Design and
Implementation“ by C.W. Fraser & D.R. Hanson
 Limited code optimization capabilities
 Code quality generally lower than GCC‘s
 Translation of C-source into data flow graphs (C language operators + type and size information)
 Inappropriate for high-efficiency embedded code
based on slide by Désirée Kraus, Inf 12, 2005

 P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006

Fri2 - 5 -

Universität Dortmund

Existing Compiler Frameworks: EDG
C++ frontend by EDG
Supports Standard C++, Microsoft C/C++,
GNU C/C++ and other
 High-level IR keeping names, type information and line
numbers
 Loss of information about original source code
 Inappropriate for source to source level transformations  Backends for generating C and C++ code
 transformation: C++ → C
 Loss of code quality for C++ due to intermediate step
based on slide by Désirée Kraus, Inf 12, 2005

 P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006

Fri2 - 6 -

Universität Dortmund

Existing Compiler Frameworks: Cosy
Compiler system with frontends for C, C++,
Fortran and Java
 Developed by ACE (Associated Compiler Experts)
 Common high-level Intermediate Representation
- standard optimization passes
- modular extensibility
 Lowering in further steps
 Commercial tool with professional support
 Uses C++ frontend by EDG (Edison Design Group)
 Significant costs

based on slide by Désirée Kraus, Inf 12, 2005

 P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006

Fri2 - 7 -

Universität Dortmund

Existing Compiler Frameworks: SUIF
Stanford University Intermediate Format
compiler for ANSI-C and Fortran 77
 High-level IR: „high-SUIF“
 Output of high-level C-Code with minor changes
- code-quality remains almost constant
- appropriate for source to source transformations
 Reduction to lists of instructions („low-SUIF“)
 Optimizations
 Version problems SUIF 1 outdated, SUIF 2 never quite
completed

based...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay on Compiler Construction
  • Compiler Essay
  • Compiler Construction Essay
  • An Overview of a Compiler Essay
  • Essay on Structure of Compiler
  • Compiler Design Essay
  • Compiler Phases Essay
  • Compiler Construction Quiz Essay

Become a StudyMode Member

Sign Up - It's Free