×

Search anything:

Types of compilers

Free book on Dynamic Programming

Get this book -> Problems on Array: For Interviews and Competitive Programming

A compiler is a program that translates source code into machine code that can be executed by a computer. In this article we explore various types of compilers.

Table of contents.

  1. Introduction.
  2. Types of compilers.
  3. Summary.
  4. References.

Introduction.

A compiler is a program that translates a program written in a high level language to an equivalent in machine code.

Apart from this translation a compiler is also responsible for reporting and handling of errors in the program, helping with debugging, optimizing the source code and do all this very fast while preserving the original meaning of the source code.

Compilers come in different forms, these include;

  • Cross compilers
  • Incremental compilers.
  • Just-in-time(JIT) compilers.
  • Ahead-of-time(AOT) compilers.
  • Threaded code compiler.
  • Load and go compiler.
  • Parallelizing compiler.

We can also classify compilers in regard to how data passes through them, in this case we have;

  • Single pass compilers.
  • Multi-pass compilers.

Types of compilers.

Single pass compilers.

These compilers like the name suggest make one pass over source code, in this pass, code is analyzed, parsed and generated all at once.
A single-pass compiler aims to get as much information from the one pass as quickly as possible and not fill up the store with too much information.

An example is the turbo pascal compiler.

Multi-pass compiler.

Also known as a wide compiler, it consists of multiple small programs that play a part in translating the code.

Compilation with such a compiler consists of stages whereby at each stage source code is transformed into an intermediate representation.
These compilers uses less memory compared to single pass compilers.

Examples include gcc compiler, java compier

Incremental compilers.

Take for example we are writing code and have already compiled it, normally a traditional compiler would have to recompile the whole thing to generate an executable but in these types of compilers, only modified source code is recompiled while the rest is left untouched.

These compilers are less time consuming, they are also useful for maintenance purposes.
Incremental compilations results in code similar to the original code in a previous full compilation.

Examples include, C/C++ GNU Compiler, Java eclipse platform.

Load and go compilers.

Code produced from such compilers is either ready for execution or in need of further transformation by a linker and loader into absolute code.
If it generates code ready for execution this means that steps such as compilation, assembly, linking and loading are not separate from the execution of the program.

An example is the WATFOR compiler,

Threaded code compiler.

This is a compiler implementation used in the implementation of virtual machine interpreters, that is, code generated here will mostly consist of subroutines or a sequence of system calls of code that needs to be processed by a system interpreter.

During compilation the compiler's job is to replace the system calls or subroutines with binary code.

An example of a threaded compiler is the Forth compiler,

Parallelizing compiler.

Writing code that is parallel is a very time consuming task. These compilers are used to convert source code into code that is parallel.

First it converts the source code into an IR such as an AST after which it performs transformations and optimizations in this way making it parallel, this code is now spread over multiple processors and executes concurrently.

Examples include, the Vector Fabrics, B.V compiler, the SUIF compiler system.

Just-in-time compiler.

A compiler of this kind converts bytecode into an instruction set that can be read by a machine's processor.
Such compiler find uses in cases where we need to improve or optimize performance of an application runtime.

An example is the java JIT compiler which turns java bytecode - a program containing instructions pending interpretation, into an instruction set that can be read and processed by a CPU. These compilers are used in the Java Runtime Environment for optimizing the performance of java applications.

Another examples is the CLR (Common Language Runtime) compiler for C#.

Ahead of time compilation.

This type of compilation is whereby we first optimize and generate code before executing the program.
It is used in systems that work on byte code for example it will allow compiling java classes into native code for subsequent executions of the same program.

An example of a AOT compiler is the High Performance Erlang Project (HiPE) AOT for Erlang programming language.

Cross compiler.

Cross compilation involves compiling code from one computer system(target) to another different system (host).
A cross compiler can create an executable for a different platform other than the one that it is currently running on or created in.

An example is GCC compiler implemented as a cross compiler.

Summary.

We have discussed different types of compilers and given a short note of their different purposes.

Types of compilers
Share this