我是在3个地址代码中做对还是错?
今天,我在大学的编译器建设决赛纸上完成了。 决赛论文包括一个问题,要求我将循环转换为3个地址代码。 它要求我转换的功能是:
for(i=1;i<=10;i++) x=y+z
所以,我确实循环展开并将给定语句转换为等效表达式:
x=(y+z)^10
然后,我制作了转换的代码的3个编码:
请告诉我是否正确。
Today, I'm done with my Compiler Construction finals paper at university.
The finals paper included a question that asked me to convert a for loop into 3-address code.
The function it asked me to convert was:
for(i=1;i<=10;i++) x=y+z
So, I did loop unrolling and converted the given statements to the equivalent expression:
x=(y+z)^10
Then, I made 3-address code of the converted code:
Please let me know if it is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的转换代码是错误的。
在原始内容中,X并不取决于X的过去版本,使For Loop Dead Code和 @Peter Cordes所说的无用的循环展开。如果您寻找正确的答案,则正确的未优化答案将是:
而正确的优化答案将是:
Your converted code is wrong.
In the original, x is not dependent on past versions of x making the for loop dead code and loop unrolling useless as @Peter Cordes stated. If your looking for the correct answer, the correct non-optimized answer would be:
While, the correct optimized answer would be: