Related articles |
---|
Three Address Code smitha_chandran@yahoo.com (2000-09-11) |
Re: Three Address Code Sid-Ahmed-Ali.TOUATI@inria.fr (Sid Ahmed Ali TOUATI) (2000-09-13) |
Re: Three Address Code tnaran@direct.ca (Travers Naran) (2000-09-13) |
Re: Three Address Code tnaran@direct.ca (Travers Naran) (2000-09-15) |
Re: Three Address Code dancohen@nospam.canuck.com (Dan Cohen) (2000-09-15) |
Re: Three Address Code leupers@ls12.cs.uni-dortmund.de (Rainer Leupers) (2000-09-17) |
Eff cient 3-address code in C? (was Re: Three Address Code) tnaran@direct.ca (Travers Naran) (2000-09-21) |
From: | Rainer Leupers <leupers@ls12.cs.uni-dortmund.de> |
Newsgroups: | comp.compilers |
Date: | 17 Sep 2000 22:56:52 -0400 |
Organization: | University of Dortmund, Computer Science 12 |
References: | 00-09-088 |
Keywords: | code |
smitha_chandran@yahoo.com wrote:
>
> I would like to know if Three Address Code can be implemented in some
> way other then quadruple or triples.
In our C compiler platform LANCE, the three address code intermediate
representation (IR) is represented in the form of low-level C
statements.
The advantage of this is that the IR can be compiled
just like the original C source. This feature can be
used for validation of the C frontend and
the IR optimization passes.
I attach a small example that illustrates the translation
from C code to three address code.
/*******************************************************
original C code
*******************************************************/
int A[10];
int f(int x,int y)
{
return x + y - 1;
}
void main()
{
int a,i;
a = 1;
for (i = 0; i < 10; i++)
{
a += i > 1 ? A[i] : f(2,3);
}
}
/*******************************************************
three address IR code
*******************************************************/
int A[10];
int f(int x_3,int y_4)
{
int t1;
int t2;
/* 7 "demo.c" */
/* return x + y - 1; */
t1 = x_3 + y_4;
t2 = t1 - 1;
return t2;
}
void main()
{
int a_7;
int i_8;
int t3;
int t4;
int t5;
int t14;
int t6;
char *t7;
int t8;
char *t9;
int *t10;
int t11;
int t12;
int t13;
/* 14 "demo.c" */
/* a = 1; */
a_7 = 1;
/* 15 "demo.c" */
/* for (i = 0; i < 10; i++) */
i_8 = 0;
LL5:
/* 17 "demo.c" */
/* a += i > 1 ? A[i] : f(2,3); */
t6 = i_8 > 1;
if (t6) goto LL3;
t11 = f(2,3);
t12 = t11;
goto LL4;
LL3:
t9 = (char *)A;
t8 = i_8 * 4;
t7 = t9 + t8;
t10 = (int *)t7;
t12 = *t10;
LL4:
t13 = a_7 + t12;
a_7 = t13;
/* 15 "demo.c" */
/* for (i = 0; i < 10; i++) */
t5 = i_8 + 1;
i_8 = t5;
t3 = t5 < 10;
if (t3) goto LL5;
return;
}
--
Dr. Rainer Leupers
University of Dortmund, Dept. of Computer Science 12
Otto-Hahn-Str. 16, Room E23, D-44221 Dortmund, Germany
phone: +49 (0)231 755-6151, fax: -6116, mobile: +49 (0)177 2131146
email (office): leupers@ls12.cs.uni-dortmund.de
email (home): rainer@leupers.de
http://ls12-www.cs.uni-dortmund.de/~leupers
Return to the
comp.compilers page.
Search the
comp.compilers archives again.