29 TAC examples.pdf


文档分类:IT计算机 | 页数:约8页 举报非法文档有奖
1/ 8
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/ 8
文档列表 文档介绍
CS143 Handout #29
Autumn 2001
TAC
Handout written by Maggie Johnson and revised by me.
Three address code
Three-address code (TAC) will be the intermediate representation used in our piler. It is
essentially a generic assembly language that falls in the lower-end of the mid-level IRs. Some
variant of 2, 3 or 4 address code is monly used as an IR, since it maps well to most
assembly languages.
Our TAC is a sequence of instructions, each of which can have at most three operands. The
operands could be two operands to a binary arithmetic operator and the third the result location, or
an operand pare to zero and a second location to branch to, and so on. For example, below
on the left is an arithmetic expression and on the right, is a translation into TAC:
a = b * c + b * d _t1 = b * c;
_t2 = b * d;
_t3 = _t1 + _t2;
a = _t3;
Notice the use of temp variables created by piler as needed to keep the number of operands
down to three. Of course, it's a little plicated than the above example, because we have to
translate branching and looping instructions, as well as function and method calls. Here is an
example of the TAC branching instructions used to translate an if-statement:
if (a < b + c) _t1 = b + c;
a = a - c; _t2 = a < _t1;
c = b * c; IfZ _t2 Goto _L0;
_t3 = a - c;
a = _3;
_L0: _t4 = b * c;
c = _t4;
And here is an example of the TAC transla

29 TAC examples 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数 8
  • 收藏数 0 收藏
  • 顶次数 0
  • 上传人 中国课件站
  • 文件大小 0 KB
  • 时间2011-09-06
最近更新