Introduction

A compiler is a translator that converts the high-level language into the machine language.

The main purpose of compiler is to change the code written in one language without changing the meaning of the program.

When you execute a program which is written in HLL programming language then it executes into two parts.

Phases of Compilation

The compilation process contains the sequence of various phases.

Each phase takes source program in one representation and produces output in another representation. Each phase takes input from its previous stage.

Lexical analyzer phase takes source code as input.

Syntax analysis phase takes tokens as input and generates a parse tree as output.

Semantic analysis phase checks whether the parse tree follows the rules of language.

Intermediate code generation generates the source code into the intermediate code.

Code optimization is an optional phase and is used to improve the intermediate code so that the output of the program could run faster and take less space.

Code generation is the final stage and takes the optimized intermediate code as input and maps it to the target machine language. Code generator translates the intermediate code into the machine code of the specified computer.

Untitled

Passes in Compiler

One Pass is a complete traversal of the source program.

Compiler has two passes to traverse the source program.

LLVM (Case Study)