查看: 3108| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

[汇编|硬件] [Coursera] Compilers Design (Unit #4)

全局:
公开课
学校名称: Stanford University
Unit号: 4
开课时间: 2012-11-26
课程全名: Compilers Design
平台: Coursera

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 cs900601 于 2013-3-14 13:12 编辑

这是最后一个作业(我是在self-study mode中做的作业,开课时间写的是11-11-26,因为是距离最近的上一次课)

接上PA3: http://www.1point3acres.com/bbs/thread-44059-1-1.html

PA2: http://www.1point3acres.com/bbs/thread-41727-1-1.html


PA1: http://www.1point3acres.com/bbs/thread-40902-1-1.html

In this assignment, you will implement a code generator for Cool. When successfully completed, you will have a fully functional Cool compiler!
The code generator makes use of the AST constructed in PA3 and static analysis performed in PA4.
Your code generator should produce MIPS assembly code that faithfully implements any correct Cool program. There is no error recovery in code generation—all erroneous Cool programs have been detected by the front-end phases of the compiler.
As with the static analysis assignment, this assignment has considerable room for design decisions.
Your program is correct if the code it generates works correctly; how you achieve that goal is up to you.
We will suggest certain conventions that we believe will make your life easier, but you do not have to take our advice. This assignment is about twice the amount of the code of the previous programming assignment, though they share much of the same infrastructure. Start early!











上一篇:求助 UDacity上的视频下载后如何调出字幕
下一篇:[MOOC]一门从零开始手工实现C++11编译器的公开课!目测完成了就是神了!!!
🔗
 楼主| cs900601 2013-3-8 14:35:49 | 只看该作者
全局:
本帖最后由 cs900601 于 2013-3-14 13:13 编辑

2013-03-14 Update:
终于所有测试用例通过了
Code中有许多非常非常ugly的修正
其一:在进行dispatch的时候如果遇到了一个self_type,那么要注意:
   1a)dispatch的函数名,也就是Dispatch Table所在的位置是无法在编译时指定的;
   1b)但是dispatch table这个表当中的offset是可以在编译时指定的。因为在同一条继承链上的所有类的某个共同拥有的函数其offset值是一样的
其二:在case的时候,case中的分支需要指向相同的store,比如以下的code
case foo in
    a:Class1 => a.bar();
    b:Class2 => b.bar();
    c:Class3 => c.bar();
esac
如果bar的功能是将foo里面的某个成员变量加一,那么上述case语句执行n遍之后,foo里面那个成员变量就加了n
所以:在第一个分支中,a要指向与foo相同的store,具体来说就是如果foo是一个成员变量,那foo的store就是$A0 + 12 + 偏移量;如果foo是一个实际参数,那么foo的store就是$FP +堆栈大小 + 参数的序号;如果foo是个普通的在let中被定义的变量,那它的store就是$S1 ~ $S6或是(在临时变量多于6个的时候)$FP + 4*x,其中x是临时变量的序号减去6.

总体来说只要有耐心就能做出来了。



回复

使用道具 举报

无效楼层,该帖已经被删除
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表