Is gcc C compiler written in C itself ? Or is it written in Assembly ? If the compiler is written in C, then what is the compiler used to compile the compiler code ?
gcc C编译器是用C编写的吗?还是用汇编语言写的?如果编译器是用C编写的,那么编译器用来编译编译编译器代码的是什么?
3 个解决方案
#1
85
The specific history to gcc is given at the GCC Wiki. The more general point is that compilers are generally originally compiled with some other compiler until they are powerful enough to compile themselves. Alternately, it is possible to write a basic compiler that can handle a subset of your features in assembler, and build up from there. But again, this is almost never needed anymore. There are plenty of compilers available, in a variety of languages. Even when Stephen Johnson was writing pcc (one of the first C compilers), there were compilers for B available, along with many other languages. gcc had several compilers to pick from to build it originally, and RMS says he was using the Pastel compiler at least during his initial development.
gcc的具体历史在gcc Wiki中给出。更一般的观点是,编译器通常是与其他编译器一起编译的,直到它们足够强大到可以自己编译为止。或者,也可以编写一个基本的编译器,它可以在assembler中处理您的特性的一个子集,并在此基础上进行构建。但是,这几乎再也不需要了。在各种语言中,有大量的编译器可用。即使在Stephen Johnson编写pcc(第一批C编译器之一)时,也有可用的B编译器,以及许多其他语言。gcc有几个编译器可以选择,以便最初构建它。RMS说,至少在最初的开发过程中,他使用的是淡色编译器。
Remember, there is no requirement that a C compiler be written in C. You could write it in Perl if you wanted to. There is no requirement that a compiler for a given platform be originally written on that platform (embedded systems almost always are compiled on some other system). So there are many ways to get yourself bootstrapped.
记住,不需要用C语言编写C编译器,如果需要,可以用Perl编写。不需要为给定平台编写编译器(嵌入式系统几乎总是在其他系统上编译)。所以有很多方法可以让你自己独立。
This question has some interesting subtleties related to the first instance of bootstrapping the compiler. If you were very clever, you could make use of that bootstrap to do something incredible, brilliant and terrifying.
这个问题有一些与引导编译器的第一个实例相关的有趣的微妙之处。如果你很聪明,你可以利用这个引导程序去做一些不可思议、精彩和可怕的事情。
#2
49
Originally it was written in some assembly language then it began to dog food itself.
最初,它是用汇编语言写成的,然后它开始限制食物本身。
#3
3
While this is obviously just a very rough indicator, I found this quick listing on the gcc-5.1.0-src/gcc/
directory interesting. This directory contains the main sources of GCC itself (except for runtime libraries).
虽然这显然只是一个非常粗略的指标,但我发现gcc-5.1.0-src/gcc/目录上的这个快速列表很有趣。这个目录包含GCC本身的主要来源(运行时库除外)。
Here are the top file-counts (over 100) grouped by extension dominated by C and C++ files.
下面是由C和c++文件主导的扩展分组的*文件计数(超过100个)。
112 .opt
118 .def
140 .cc
185 .x
250 .exp
353 .md
366 .mm
414 .f
430 .f03
521 .m
625 .a
1082 .go
1371 .h
1602 .ads
1655 .adb
1828 .ada
3860 .f90
11231 .C // C++
23811 .c // C
Please note that nowadays GCC
refers to the GNU Compiler Collection, not just the GNU C Compiler.
请注意,现在GCC指的是GNU编译器集合,而不仅仅是GNU C编译器。
6.3 The gcc Subdirectory
gcc 6.3子目录
The gcc directory contains many files that are part of the C sources of GCC, other files used as part of the configuration and build process, and subdirectories including documentation and a testsuite.
gcc目录包含许多文件,这些文件是gcc C源代码的一部分,其他文件用作配置和构建过程的一部分,子目录包括文档和testsuite。
Reference: https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html
参考:https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html
#1
85
The specific history to gcc is given at the GCC Wiki. The more general point is that compilers are generally originally compiled with some other compiler until they are powerful enough to compile themselves. Alternately, it is possible to write a basic compiler that can handle a subset of your features in assembler, and build up from there. But again, this is almost never needed anymore. There are plenty of compilers available, in a variety of languages. Even when Stephen Johnson was writing pcc (one of the first C compilers), there were compilers for B available, along with many other languages. gcc had several compilers to pick from to build it originally, and RMS says he was using the Pastel compiler at least during his initial development.
gcc的具体历史在gcc Wiki中给出。更一般的观点是,编译器通常是与其他编译器一起编译的,直到它们足够强大到可以自己编译为止。或者,也可以编写一个基本的编译器,它可以在assembler中处理您的特性的一个子集,并在此基础上进行构建。但是,这几乎再也不需要了。在各种语言中,有大量的编译器可用。即使在Stephen Johnson编写pcc(第一批C编译器之一)时,也有可用的B编译器,以及许多其他语言。gcc有几个编译器可以选择,以便最初构建它。RMS说,至少在最初的开发过程中,他使用的是淡色编译器。
Remember, there is no requirement that a C compiler be written in C. You could write it in Perl if you wanted to. There is no requirement that a compiler for a given platform be originally written on that platform (embedded systems almost always are compiled on some other system). So there are many ways to get yourself bootstrapped.
记住,不需要用C语言编写C编译器,如果需要,可以用Perl编写。不需要为给定平台编写编译器(嵌入式系统几乎总是在其他系统上编译)。所以有很多方法可以让你自己独立。
This question has some interesting subtleties related to the first instance of bootstrapping the compiler. If you were very clever, you could make use of that bootstrap to do something incredible, brilliant and terrifying.
这个问题有一些与引导编译器的第一个实例相关的有趣的微妙之处。如果你很聪明,你可以利用这个引导程序去做一些不可思议、精彩和可怕的事情。
#2
49
Originally it was written in some assembly language then it began to dog food itself.
最初,它是用汇编语言写成的,然后它开始限制食物本身。
#3
3
While this is obviously just a very rough indicator, I found this quick listing on the gcc-5.1.0-src/gcc/
directory interesting. This directory contains the main sources of GCC itself (except for runtime libraries).
虽然这显然只是一个非常粗略的指标,但我发现gcc-5.1.0-src/gcc/目录上的这个快速列表很有趣。这个目录包含GCC本身的主要来源(运行时库除外)。
Here are the top file-counts (over 100) grouped by extension dominated by C and C++ files.
下面是由C和c++文件主导的扩展分组的*文件计数(超过100个)。
112 .opt
118 .def
140 .cc
185 .x
250 .exp
353 .md
366 .mm
414 .f
430 .f03
521 .m
625 .a
1082 .go
1371 .h
1602 .ads
1655 .adb
1828 .ada
3860 .f90
11231 .C // C++
23811 .c // C
Please note that nowadays GCC
refers to the GNU Compiler Collection, not just the GNU C Compiler.
请注意,现在GCC指的是GNU编译器集合,而不仅仅是GNU C编译器。
6.3 The gcc Subdirectory
gcc 6.3子目录
The gcc directory contains many files that are part of the C sources of GCC, other files used as part of the configuration and build process, and subdirectories including documentation and a testsuite.
gcc目录包含许多文件,这些文件是gcc C源代码的一部分,其他文件用作配置和构建过程的一部分,子目录包括文档和testsuite。
Reference: https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html
参考:https://gcc.gnu.org/onlinedocs/gccint/gcc-Directory.html