Related articles |
---|
A doubt in "Compiler Design in C" about constant folding mayur_naik@my-deja.com (1999-07-21) |
Re: A doubt in "Compiler Design in C" about constant folding root@candle.pha.pa.us (1999-07-23) |
Re: A doubt in "Compiler Design in C" about constant folding mah@colorado.edu (ma haibing) (1999-07-23) |
From: | mayur_naik@my-deja.com |
Newsgroups: | comp.compilers |
Date: | 21 Jul 1999 00:21:29 -0400 |
Organization: | Deja.com - Share what you know. Learn what you don't. |
Keywords: | books, question, comment |
Hello!
This is with reference to the source code for the syntax directed
translation of a relational expression (<, >, <=, >=, ==, !=) in the C
compiler presented in the book "Compiler Design in C" by
Allen I. Holub.
When given the input (20 < 10) the compiler generates something like:
if (20 < 10) goto T1;
F1:
X1 := 0;
goto E1;
T1:
X1 := 1;
E1:
Same is the case with the logical &&, ||, and ! operators. I wanted to
know, why doesn't the author do CONSTANT FOLDING here? He does that
for the arithmetic operators +, -, *, etc. Then why not for the logical
operators?
Thanks and Regards,
Mayur
[Useful constant folding here also involves dead code elimination, since
the "if" statement turns into if(0), the goto T1 disappears, making T1
unreachable so X1 := 1 disappears, making the goto E1 redundant. Perhaps
he didn't want to go into all that. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.