Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between one pass and multi pass compilers?

I have seen a lot of posts regarding one pass and multi pass compilers but i dont seem to get the point.

  • What are one pass compilers?

  • what are multi pass compilers?

  • What is the main difference between them ?

  • Can anyone provide the difference between them in a very simple language?

like image 572
Tilak Raj Avatar asked Feb 27 '16 18:02

Tilak Raj


People also ask

What is the difference between single pass and multipass compiler?

The difference between single pass and multipass compiler is that a single pass compiler is a compiler that passes the source code through each compilation unit only once while a multipass compiler separates compilation into multiple passes, where each pass would continue with the result of the previous pass.

Why is multipass compiler better than single pass compiler?

A one pass/single pass compiler is that type of compiler that passes through the part of each compilation unit exactly once. Single pass compiler is faster and smaller than the multi pass compiler. As a disadvantage of single pass compiler is that it is less efficient in comparison with multipass compiler.

What are advantages and disadvantages of single pass compiler and multi-pass compiler?

A one-pass compiler is faster than multi-pass compilers. Single-pass Compiler : Advantage: More effective than multi-pass compilers in the compiler point of view. Disadvantage: It compiles less efficient programs.

What is the difference between passes and phases of compiler?

Pass : A pass refers to the traversal of a compiler through the entire program. Phase : A phase of a compiler is a distinguishable stage, which takes input from the previous stage, processes and yields output that can be used as input for the next stage.


1 Answers

The origin of the term multi-pass comes from a time when computers had a lot less memory. Compilers need a lot of memory, and in a small memory machine, this is hard to manage.

So the original idea was a compiler ran in multiple passes. The first pass read the source code, and did basic tasks such as syntax checking, maybe building a symbol table, and then wrote its results to a disk file for the second pass. Each successive pass N would read the previous pass's result, and change the program representation to move it further and further towards machine code, and write out its results for pass N+1 to read. This process repeated until the final pass produced the final code. Many compilers could get by a few ("multi") passes; there were reputed compilers with dozens of passes built on really old machines.

(This same concept applies to so called "two pass assemblers": first pass reads the assembler source code, syntax checks, figures out what location values should be used for label symbols; second pass produces object code using the knowledge of the symbol locations assigned in the first pass).

Memory is now larger, and it is quite practical for read source code for every very big programs into memory, have the compiler do all its work in the memory of a single process, and write the object code. You still see some analogical remnants of this in the concept of linkers; they glue together multiple object modules ("the first pass") into a single binary.

If you look at compiler internally, they operate in phases. Typical phases might be:

*  Parse and syntax check
*  Build symbol tables
*  Perform semantic sanity check
*  Determine control flow
*  Determine data flow
*  Generate some "intermediate" language (representing abstract instructions)
*  Optimize the intermediate language
*  Generate machine code from the optimized language

What a specific compiler does for phases varies from compiler to compiler. Each of these steps pushes the program representations closer to the final machine code. An N-pass compiler would bundle one or more of these steps into a single pass.

Back to present times, we have lots of memory; no need for a modern compiler to write the intermediate results to a disk file, so all these phases happen in the memory of a single process. You, the compiler user, don't see them. So you might call modern compilers "one pass" in the original senses of the word. Since nobody now cares, the phrase has simply fallen into disuse.

In any case, the compilers are still generally multi-phased internally. (There are compilers that do all of these steps in what amounts a single phase; normally, they cannot do a lot of optmization).

like image 94
Ira Baxter Avatar answered Oct 23 '22 07:10

Ira Baxter