龙书第二版下载

一月 24, 2008 at 5:17 下午 | In Default, Technology, compiler | 5 Comments

compiler-aho.pdf
今天终于把龙书第二版的电子书传上去了。不知道链接什么时候会失效。
失误,一开始写成第三版了

阅读(2941 次)

龙书第二版

十一月 12, 2007 at 10:31 下午 | In Default, Technology, compiler | 21 Comments

说到龙书(Dragon Book),喜欢玩编译器和程序语言的老大们肯定是人手一册,在编译器技术这一块的教科书中地位几乎有如圣经。说到这儿又要鄙视一下国产的什么编译原理教材,简直是不知所云,抄都抄得这么潦草。

计算机领域的经典著作,常常会有些“小名”或俗名,如无人不知的TAOCP,C语言圣经K&R,算法入门宝典CLR。TAOCP是书名的缩写,此书堪称最有名的算法书籍,我估计也是被完整阅读次数最少的计算机书籍,之一都省掉了。K&R和CLR都是作者名字的开头第一个字母。龙书算是比较有个性的,这个外号来自其封面。1977年,Alfred V. Aho和Jeffrey D. Ullman写了一本Principles of Compiler Design,封面是一位骑士枪挑一头绿色恐龙,因此得名龙书。到了1986年,此书升级换代,书名变成了Compilers: Principles, Techniques and Tools,沿用至今,作者增加了Ravi Sethi。封面依然是一位骑士和一头恐龙,只不过恐龙变成了红色,骑士则坐在了电脑前。仔细看的话,发现龙身上纹身“Complexity of Compiler Design”,骑士全副武装,盔甲上书“Data Flow Analysis”,夹着一把写着”LALR Parser Generator”的宝剑,盾牌上则写着”Syntax Directed Translation”。
Continue reading 龙书第二版…

阅读(4942 次)

Creating library with GCC

七月 24, 2007 at 11:22 上午 | In Default, Technology, compiler | 2 Comments

A Short Definition

A static library is basically a collection of object files.During the linking phase of compilation,the static library,or the object files in it, will be simply copied into the target executable file.Static libraries usually ends with a “.a” suffix in UNIX variants(including MinGW) and “.lib” in Windows.

A shared library,also called dynamic library(on Windows,they are the familiar dlls,the origin of “DLL Hell”) is “dynamically” linked into program in runtime.Why I use “dynamically” here is that during compilation the object files contained in shared library are not inserted into the final executable file;instead, when the program is started, a program in the system (called a dynamic loader) checks out which shared libraries were linked with the program, loads them to memory, and attaches them to the copy of the program in memory.

Creating Static Library

Suppose you have some object files with the name util1.o,util2.o,….Then then following command will create a static library “libutil.a” and puts all the objs into it:

ar rcs libutil.a util1.o util2.o ...

Note that the static library must start with “lib” and have the suffix “.a

ar can be used to creating,modifying and checking static libraries.
Continue reading Creating library with GCC…

阅读(1774 次)

How GCC Divide

七月 17, 2007 at 1:57 上午 | In Default, Technology, compiler | 2 Comments

While I’m working on the module of my project which translating arithmetic operations into machine code,I think I should take a look at how gcc does it,especially (one of)the most wierd operation in i386 instruction set,div.After examining gcc’s output(using -S option when compiling),I find something interesting.When divisor is a constant integer,for example,an expression like x/3 (assuming x is a local variable with type int)in C source code,gcc will translate it into a seemingly strange sequence of instructions:

movl  $1431655766, %eax
imull x
movl  %edx, %ecx
movl  x, %eax
sarl  $31, %eax
subl  %eax, %ecx

(the result is stored in %ecx)

Continue reading How GCC Divide…

阅读(1414 次)

Restart my Compiler project

六月 26, 2007 at 9:16 下午 | In Default, Technology, compiler | No Comments

考完试了,有几天空闲时间。我想起还有个建设中的编译器被我遗忘在目录深处,决定利用这几天工夫好好来写点代码。

这个玩具编译器(我的计划是未来某一天它不再是一个toy language,我设想了许多美好的特性,但我现在还没有足够的技术和时间来实现他们)的前端已经完工。编译器前端——词法分析、语法分析——在教科书上占一半的篇幅,涉及到不少理论知识,但实际上是个无聊的工作。而code generation则是麻烦而繁琐的。网上可以找到全套的工具——从flex、bison这样的前端生成器,到MLRISC这样完备的后端,但我还是想自己动手写一遍。 我现在去看几个月以前写的code generation,惊奇于这样丑陋而复杂的代码居然(貌似)是对的。

我的目标是生成机器代码,这两天花了不少功夫研究IA32处理器的浮点运算,深刻地认识到FPU是一个多么难看的设计,让我的代码增加了无数的条件分支和switch。想了解一下MIPS在这个问题上是怎么处理的。string,class等已经初步提上日程。至于我幻想中的gc及lambda expression,high-order function,continuation等一干functional特性,现在还遥遥无期。

从书签里翻出一篇老文章,一直没细读,Modern x86 assembly (blogspot….被和谐掉了。同志们上代理。),里面着重谈了alignment(对齐)和caching(缓存)。对现代的计算机架构,这两样东西对性能有极其重要的影响。对齐主要是编译器考虑的问题;而cache的影响则更为微妙。准备好好学习一下。

阅读(1091 次)

Zero Sound , powered by 赛族 & WordPress MU | Theme: Pool by Borja Fernandez.
Entries and comments feeds.