Académique Documents
Professionnel Documents
Culture Documents
COMPILERS
HW-2
Sawar Sagwal, 20171013
Ques 3
There are two ways to compile a compiler:
1. The simplest way is to write the entire compiler in some other existing language and
then compiling it.
2. By bootstrapping: The process of compiling a compiler is analogous to the chicken
and egg problem because we can ask the question, how did the first compiler was
compiled. This can be done using assembly, or write basic features as machine
instructions and use it to work on an advanced language which can be the first
assembler. The technique of using the compiler written for the source programming
language to compile the compiler is called bootstrapping and such compilers are
called self-compiling. This technique requires some basic/core set of features for the
source language to be built using some other language (can be machine language).
The process can then be used progressively to get higher levels of abstractions.
Bootstrapping requires the following steps: (from wikipedia)
a. Prepare an environment for the bootstrap compiler to work with.
b. Write the bootstrap compiler
c. Compile an advanced compiler using both the bootstrap compiler.
d. Compile an advanced compiler using the compiler from the previous step.
Another example of the chicken or egg problem is booting a computer, wherein we can ask
how was the first software loaded. Here also bootstrapping is used. Basic machine
instruction loads the BIOS which loads the bootloader and so on.
Compiling GCC: GCC is also compiled using bootstrapping. GCC is itself written in C and
C++. Bootstrapping GCC involves first building the tools which are necessary to build the
compiler and creating basic/core features to build the rest of the features (bootstrapping).
The runtime libraries are then built using the compiler built after bootstrapping.
So the whole process is: (GCC Source code) => (Intermediate Representation) => (Assembly
code) => (Machine code) => (linking and generating the executable)
Compiling LLVM: LLVM is written in a subset of C++ and requires relatively modern
features of C++. It is compiled using GCC but can also be compiled through clang or icc. The
process of generating assembly is omitted (as the assembly code is not generated).
The process is: (C++ source code) => (Intermediate representation) => (machine code) =>
(linking to generate an executable)
Ques 4
JDK version:
The following program was used (instead of integer, biginteger was used to avoid overflow)
import java.math.BigInteger;
2
5 0.172 s 0.125 s
6 0.125 s 1.016 s
7 0.406 s 9.844 s
8 2.109 s 1m 47.438 s
Ques 5
3
4
5