Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

compiler construction - Reaching Definitions analysis - is my solution correct

I am asked to write the reaching definition for the following code and I am wondering if my solution is correct? am I even on the right track? I truly appreciate any help or hint. Thank you.

Code:

a = 0;
while (a < 100) {
    b = a + 1
    c = c + b
    a = b * 2
}
return c;

Step #1: finding blocks and labeling

a = 0;             // block 1  | a1

while (a < 100)    // block 2  |

    b = a + 1      // block 3  | b2
    c = c + b                  | c3
    a = b * 2                  | a3

return c;          // block 3  | 

Step #2: finding GEN and KILL sets for each block

BLOCK GEN KILL
1 a1 a3
2 ? ?
3 b3, c3, a3 a1
4 ? ?
question from:https://stackoverflow.com/questions/66059602/reaching-definitions-analysis-is-my-solution-correct

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have a look at this example: https://engineering.purdue.edu/~milind/ece573/2011spring/ps8-sol.pdf

The code that is analyzed in that example is slightly more complex than yours, but the entire solution is explained in great detail.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...