一遍和多遍编译器之间的区别? [英] Difference between one pass and multi pass compilers?

查看:440
本文介绍了一遍和多遍编译器之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多关于一次通过多次通过编译器的帖子,但我似乎没明白这一点。

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


  • 什么是一遍编译器?

什么是多遍编译器?

它们之间的主要区别是什么?

What is the main difference between them ?

谁能用一种非常简单的语言提供它们之间的区别?

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

推荐答案

术语多次通过 的起源是计算机内存不足的时候。编译器需要大量内存,而在小型内存计算机中,这很难管理。

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.

因此,最初的想法是编译器多次运行。第一遍读取源代码,并执行诸如语法检查之类的基本任务,可能会构建符号表,然后将其结果写入磁盘文件以进行第二遍。每次连续N次读取前一次的结果,并更改程序表示形式,将其逐步移向机器代码,然后将其结果写出,以通过N + 1次读取。重复此过程,直到最终通过产生最终代码为止。许多编译器可以通过几次(多次)处理;有一些著名的编译器,它们在非常老的机器上构建了许多遍。

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).

内存现在更大了,对于读取源代码来说是相当实用的对于将每个非常大的程序存入内存,让编译器在单个进程的内存中完成所有工作,并编写目标代码。您仍然可以在 linkers 概念中看到一些类似的残迹;它们将多个对象模块(第一遍)粘合到一个二进制文件中。

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

特定编译器在阶段中所做的工作因编译器而异。每个步骤都使程序表示更接近最终的机器代码。 N-pass编译器会将这些步骤中的一个或多个捆绑为一个步骤。

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).

这篇关于一遍和多遍编译器之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆