domingo, 5 de febrero de 2017

Internals of GCC (Comment)

Compiler design is a subject that might not interest many programmers but it is the backbone of our code. Without them we couldn't write software as we now it today. Understanding how a compiler works allows us to understand how is our code interpreted and there is nothing better than knowing more about the thing that makes the magic come to life. As told in the podcast, it might not be really important but it is good to know it, just as being aware of how your car engine works, you never know when this can come in handy. 

The GNU gcc is one of the most used compilers in the world. One of the key points about is it's portability to many OS (Windows, MacOs, Linux, etc.) and it is very flexible to take source as C/C++, Java, Ada, Fortran to produce object code. This compiler is very modular, it has a front-end, middle-end and a back-end (Each of them have their own responsibility). Any source programming language mentioned comes inside the compiler and it checks if everything is ok. The compiler creates a tree (data structure) to give logic to the operations in the code. Then the middle-end creates a similar tree but slightly lower level representation with possibly some optimizations in space or time.

RTL then makes like a low level representation of the source code. This cannot be recognized anymore because it doesn't have any of the high level language references that you coded. Then the register allocation comes in and it assigns all the instructions. It stores frequently used variables in some registers to make it more efficient to run. RTL matches the registers with specific assembly instructions (using patterns) and it makes it possible to do the operations between them. Knowing which architecture are you going to use can allow you to create code that will run more efficiently on it.  

References:

Arno, 2007. "Episode 61: Internals of GCC". Software Engineering Radio. Retrieved February 5th 2017 in: http://www.se-radio.net/2007/07/episode-61-internals-of-gcc/

No hay comentarios:

Publicar un comentario