Pass in Compiler Design

Estudies4you

Pass

  • In an implementation of a compiler, portion of one or more phases are combined into a module called pass
  • It is a group of phases implemented together
  • A pass reads the source program of the output of the previous pass, makes the transformations specified by its phases, and writes output into an intermediate file, which is read by a subsequent pass
  • In pass, the operations of phases may be interleaved
  • Generally, the lexical analysis, scanner, semantic analysis and intermediate code generation are grouped into one pass whereas the remaining phases into another pass
  • Number of passes to keep is generally dependent upon the structure of the source language and the environment in which the compiler must operate
  • It is better to have less number of passes as it takes time to read and write intermediate files
  • However it is not always possible to have a single pass instead of several passes, as sometimes there may be a need to keep the entire program in memory because one phase may need information in a different order than a previous phase produces
Single pass: All phases are combined into single
Multi pass: More than one phase are combined into a number of groups called multi pass

Difference between Multi pass and Single pass
Multi pass
Single pass
Uses less space than single pass compilers, since the space occupied by the compiler for one pass can be reused by another pass
Uses more space than multi pass compilers
Slower than single pass compiler, due to reading and writing of intermediate files
Faster than multi pass as there is no reading and writing of intermediate files
Works fine with small memory
Works fine with large memory

Difference between a Phase and Pass of a Compiler:
Phase
Pass
In compilers, the process of compilation can be carried out with the help of various phases such as lexical analysis, syntax analysis, intermediate code generation, code optimization and code generation
In case of passes, various phases are combined together to form a single pass. An input program can be compiled using a single pass or using two passes
Different groups of phase from corresponding front end and back ends of the compilers
Compiling a source program into single pass is difficult because of forward reference that may occur in the program. Similarly if we group all the phases into a single pass then we may be forced to keep the entire program in the memory
To Top