..
2023-08-07
Compiler vs Interpreter
- $src \rightarrow compiler \rightarrow target$
- $src+input \rightarrow interpreter \rightarrow result$ This is done line by line
Objectives of Compiler Design
- Preserve the meaning of the program
- Improve the performance by optimization
Types of Output
- High level
- Pure machine code i.e without any dependencies
- Augmented machine code i.e OS dependencies
- Virtual Machine code (Java Byte Code)
Types of Machine Languages
- Assembly
- Relocatable Binary
- This has relative addressing
- Absolute Binary
- This has absolute addressing The scheme of addressing is handled by the OS
I/O of compiler stages
$\xrightarrow{src} Frontend \xrightarrow{IR} Optimizer \xrightarrow{IR} Backend \xrightarrow{targ}$ Retargetting is the process of generating binaries for new processors
Frontend
$\xrightarrow{Stream\ of\ characters} Scanner \xrightarrow{Stream\ of\ tokens} Parser \xrightarrow{AST} Semantic\ Elaboration \xrightarrow{IR}$
Backend
$Instruction\ Selection \xrightarrow{\texttt{.asm}} Register\ allocation \xrightarrow{\texttt{.asm}} Instruction\ Scheduling \xrightarrow{\texttt{.asm}}$
Simple Example
a = a * 2 * b * c * d
$$\downarrow$$
<id, a> = <id, a> * <num, 2> * <id, b> * <id, c> * <id, d>