Internals of GCC
Once again we face that complicated question-
Why be interested in compilers?
According to Morgan Detters learning about them could be really useful, like when you go to the mechanic and learn a little about the function of your car you never know when that knowledge will be useful.
But, how does it work?
In simple words a compiler reads a plain source text, starts understanding the semantic content. To later produce an internal representation of that knowledge for the target platform of your choice.
There are several compilers but for practical purposes we'll talk about gcc or Gnu compiler collection: which is flexible, portable and multi platform. Having as an advantage that accepts various source inputs like: C, C++, Java, Ada and Fortran.
But, how does it achieve this flexibility?
Gcc is very modular and it's composed of 3 elements: front-end, middle-end and back-end. On the front-end (that can be swapped between c, c++ or java) different language can be parsed and then transformed to a common abstraction which is represented as a tree. This tree type represent classes and structs, it uses a list to gather all the methods and elements associated to a class.
Gcc is so portable having just a minimum c compiler which generates: gcc (itself), a c compiler (obviously), a c++ compiler and a java compiler.
Gcc is also composed of a neutral middle end which takes the output of the front end (the tree structure) which will be manipulated by different middle end passes to generate an smaller and more efficient output a RTL a representation that the back end can use.
Finally gcc has the back-end which is focused on translating the RTL into assemble language.
The front end is language dependent but architecture independent, the middle end can operate on anything and the back end (this is language neutral but architecture specific) produce specific architecture code.
Among all the inside files that gcc has there is one that takes great relevance "the machine description file" which allows gcc to match and compute RTL's, it also includes a very large amount of information of what´s available in the processor and what sort of code can be generated.
Compilers are an indispensable tool for programming. Instead of just take them for granted why not learn about them? Among them gcc is an example of how a compiler should be, being flexible, portable and multi platform, learning about gcc grant us a better insight about languages and compilers.
Reference:
http://www.se-radio.net/2007/07/episode-61-internals-of-gcc/
Why be interested in compilers?
According to Morgan Detters learning about them could be really useful, like when you go to the mechanic and learn a little about the function of your car you never know when that knowledge will be useful.
But, how does it work?
In simple words a compiler reads a plain source text, starts understanding the semantic content. To later produce an internal representation of that knowledge for the target platform of your choice.
There are several compilers but for practical purposes we'll talk about gcc or Gnu compiler collection: which is flexible, portable and multi platform. Having as an advantage that accepts various source inputs like: C, C++, Java, Ada and Fortran.
But, how does it achieve this flexibility?
Gcc is very modular and it's composed of 3 elements: front-end, middle-end and back-end. On the front-end (that can be swapped between c, c++ or java) different language can be parsed and then transformed to a common abstraction which is represented as a tree. This tree type represent classes and structs, it uses a list to gather all the methods and elements associated to a class.
Gcc is so portable having just a minimum c compiler which generates: gcc (itself), a c compiler (obviously), a c++ compiler and a java compiler.
Gcc is also composed of a neutral middle end which takes the output of the front end (the tree structure) which will be manipulated by different middle end passes to generate an smaller and more efficient output a RTL a representation that the back end can use.
Finally gcc has the back-end which is focused on translating the RTL into assemble language.
The front end is language dependent but architecture independent, the middle end can operate on anything and the back end (this is language neutral but architecture specific) produce specific architecture code.
Among all the inside files that gcc has there is one that takes great relevance "the machine description file" which allows gcc to match and compute RTL's, it also includes a very large amount of information of what´s available in the processor and what sort of code can be generated.
Compilers are an indispensable tool for programming. Instead of just take them for granted why not learn about them? Among them gcc is an example of how a compiler should be, being flexible, portable and multi platform, learning about gcc grant us a better insight about languages and compilers.
Reference:
http://www.se-radio.net/2007/07/episode-61-internals-of-gcc/
Comentarios
Publicar un comentario