Where in the GCC source code is it compiled into different assembler languages?

Where is the code in the GCC source code that actually creates the assembly for different architectures?

It's amazing how many different assembler languages ​​it compiles and how it actually does it (by looking at the source code).

Somewhere in the gcc repository or in another repo? I began to dig, but found nothing.

https://github.com/gcc-mirror/gcc

For example, here are some of the assembly generation code in V8:

https://github.com/v8/v8-git-mirror/tree/master/src/x64

Is there something equivalent for GCC?

I'm curious because this is a mystery how GCC does it, and it would be a great way to find out how compilers are actually implemented down to the build level.

+5
source share
2 answers

GCC source .md (machine description) files contain build material. GCC contains several specialized C / C ++ code generators (and some of them convert .md files to code assembly).

GCC is a very complex program. The GCC MELT documentation contains some interesting links and slides, specifically linking to the Indian GCC Resource Center

Most optimizations in GCC happen in the middle (which is mostly independent of the source language or the target system), especially with a lot of passes working on Gimple views.

The GCC repository is an SVN repository .

See also this answer , especially the images inside it.

+11
source

The actual source code for GCC is most available here:

https://gcc.gnu.org/svn.html

The software is available through SVN (subversion), a source code management system. This will be installed on many versions of Linux / UNIX, but if you are not on your platform, you can install the svn kit and then extract the source using the following command:

 svn checkout svn://gcc.gnu.org/svn/gcc/trunk SomeLocalDir 

GCC is complex and will have significant experience in understanding how an application really compiles into different architectures.

In short, GCC has three main components - front-end, mid-end, and back-end processing. The front processor has a language parsing component for understanding the syntax of languages ​​(e.g. C, C ++, Objective-C, etc.). The interface deconstructs the portable construct code, which is then transferred to the background computer for compilation into the target environment.

The middle part performs code analysis and optimization, trying to determine the priority of the code to generate the best result at the end of the complete process. Technically, optimization can occur anywhere in the process since patterns are detected during analysis.

The internal processor compiles the code into output format in the form of a tree (and not actually executable code). Based on the expected output, the "pseudo-code" is optimized for using registers, bit sizes, end values, etc. The final code is then generated during the build phase, which converts the internal code into machine executable instructions.

It is important to note that the compiler has many options for handling output formats, so you can create output for many architecture classes, usually out of the box. To cross-compile and assign compiler options, check this link:

https://gcc.gnu.org/install/configure.html

+4
source

Source: https://habr.com/ru/post/1209639/


All Articles