Search code examples
cgccassemblycompiler-construction

Where in the GCC source code does it compile to the different assembly languages?


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

Wondering how many different assembly languages it compiles to, and how it actually does this (by taking a look at the source code).

Is it in the gcc repo somewhere, or in another repo? I have started to dig around but haven't found anything.

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

For example, here is some of the assembly generating code in V8:

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

Is there anything equivalent for GCC?

I am wondering because it's a mystery how GCC does this, and it would be a great way to learn how compilers are actually implemented down to the assembly level.


Solution

  • The .md (machine description) files of GCC source contain stuff to generate assembly. GCC contains several specialized C/C++ code generators (and some of them translates the .md files into code emitting assembly).

    GCC is a very complex program. The documentation of GCC MELT (an obsolete project) contains several interesting links and slides, notably refering to the Indian GCC Resource Center

    Most of the optimizations in GCC happens in the middle-end (which is mostly independent of source language or target system), notably with many passes working on the Gimple representations.

    The GCC repo is an SVN repository.

    See also this answer, notably the pictures inside it.