Compiler knowedge -- gcc & mem management

来源:互联网 发布:深圳龙华行知小学网站 编辑:程序博客网 时间:2024/06/09 20:38

The project about compiler?

This is source address:   http://code.google.com/p/afe/wiki/ThinkingInAFE


Introduction

My comments on compiler writing

Details

on gcc
I had learned gcc in the year 2010 for several months. gcc is huge andthe code is hard to understand. It is possible to understand a certainpart of the code base, just leave other parts as abstractions.Basically,I read the codes on tree and parser. Even this part is stillvery hard to follow. They mixed lots of other interfaces, for e.g. themiddle end(gimple). For a software, if you cannot see the overallarchitecture, you cannot understand it well. I also had read somepapers of gcc summit and others'. Most of the time, the code is notdirectly expressing the meanings but for a common purpose aim, the codeintends to support as many as possible languages and targets. Till now,gcc becomes a huge system that needs a person many many time to masterthe source code well. I learned some software design skills in gcc, butthere are too much waiting there for me to decode. gcc documents arenot written well and I think the code itself is just the only rightplace to start with. Although I got some benefit from studying gccsource code, but now I will stop and change my direction to some smallscale compilers. I think to learn a small compiler source code willbenefit me much more than digging into gcc. Sometimes I even considerto learn gccv1 or v2, but I think some of the code is not worth tolearn. In the early version of gcc, the parser is generated by bison,no need to learn bison tool. So, I will miss some very good or goodsoftware techniques for not studying gcc, it is a pity. But I do nothave so much time to learn it well. My goal is to learn compilertechniques and concentrate much of my time on myself project. To writecodes, to create something useful and cool is where the happy shouldhappened, but not reading some good software code again and again. Ishould create my own things. I will stop reading gcc source code rightnow(2011/07/25) and go to other compiler. Concentrate more on the basictheories on AFE.
I will put my thoughts on learning other compilertechniques here. These thoughts should be a combination of booktheories and a practical compiler implementation details.

memory management and symbol table
Memory is a hot area for research. There are lots of ways to manage thememory.Whatever the way is, the basic semantics are "malloc" and"free". For efficiency, compiler, game engine and some kinds ofapplications have implemented special memory manage method. Whenthinking about symbol table, it is not very hard to implement and youjust define the suitable structures for the programming elements andmake some links between the elements. But when truely implementingit,it is hard. There are lots of details to cover. For example, thetype is a part that needs to be a hard consideration:
struct people
long int
int* const p
ret(int* p,...)
The above are types. Compiler should define the suitable structure that can describe these types.

using tools or hand craft
There are a bunch of compiler construction tools, each one has itsusing semantics. It is good that you can use these tools to quicklybuild something. It is bad that you loss the absolute control of yourcode, you have to obey the rules that tool enforced. Sometimes you wantto solve a problem on theory but firstly you should think about a wayof hacking that tool to make your research easily.There are lots oftricks on using the tool, you have to goole some certain usage of thattool. You can use tools to build models of your application, let yourapplication run first. In the long run, hand craft everything and getall the control of the code is the real programming.

code::blocks error
I do not know if this is an error of code blocks. But when I deleted abunch of comments in source code. An fatal inconvenience isdismissed.With those comments, when I change some bits of a grammarheader, the whole project will be compiled again, but it is really noneed to do this.




原创粉丝点击