Exploring gcc's internal components

Recently, I was very interested in compilers and how they work. Since gcc has this source, I decided that this would be the best material to study.

The first thing I realized was that it would be pointless to learn gcc if I didn’t have a basic understanding of the simple principles of compiler design. Since then, I have been diligently reading The Dragon Book, which, from what I saw, is a de facto book on compiler implementation.

No, reading this book only contributed to my desire to learn about compilers such as gcc.

In addition, I find it appropriate to say that I have an intermediate understanding of c / C ++ (otherwise, I am not trying to learn gcc without knowing c). I hope learning gcc will help me improve this.

I downloaded the latest build I could find; however, I am lost in learning the source code.

I am looking for suggestions on how to proceed. Is there a similar project that is not so massive that I could use as a step to gcc? Is there a special gcc module that could be recommended first? Are there any books that go to gcc implementation and not use? Perhaps I should stop whining and just keep reading the source until it clicks?

Any feedback is welcome.

EDIT: If you think I should study another compiler / interpreter, I would really appreciate some suggestions regarding which ones.

+6
source share
4 answers

If you want to look at a very small compiler, I would recommend the Fabrice Bellard Tiny C Compiler .

It is also worth mentioning that Fabrizio Bellard won the confusing c-code with his Obfuscated Tiny C Compiler . There is a de-perfused version, and it fits into a single file c .

This should be great if you want something small and manageable to learn.

+6
source

I will definitely look at clang / LLVM. I think the code base is very readable. One very viable option you have is to use LLVM as the back end and write your own simple lexer and parser.

+5
source

I think it's good to read the book “ruby under the microscope” and practice with developing a ruby ​​core before reading the gcc code. But you will need knowledge of ruby ​​programming. This is about ruby ​​internet.

As I know, the best book about gcc is the "ultimate gcc guide" https://www.amazon.com/Definitive-Guide-GCC- Guides-Paperback / dp / 1590595858 . Although he is a little old, I think you should read this.

0
source

Passionate about compilers, too, I learned a lot from Nicklaus Wirth’s book Algorithms + Data Structures = Programs . One of the last chapters describes the Pascal-0 languages, and the previous chapters show how to analyze and compile a very minimalistic language. Pascal-0, PL / 0 are two-stage compilers, they generate p-code, which is the "machine code" for a minimalist virtual machine (unlike Java).

This page describes the instruction set of the PL / 0 virtual machine and, at the very end, links to the PL / 0 compiler and other interesting information.

Nicklaus Wirth has always had the ability to read human-readable and well-structured code. Here is the definition of the language and many other interesting links.

The advantage of learning and using Pascal is that the language is very structured, rather than evolution from Assembler (like C). This makes compilation easier. He doesn’t even need to make several passes ...

0
source

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


All Articles