Week 9

Code generation

    1. Derive code templates for a do-while loop and a for-loop, similar to the template for while-loops, which was presented in class. solution
    2. Under which circumstances can a program store a value different from this in local variable 0? Could a peephole optimization determine such circumstances? Answer: Variable 0 can hold other values (a) if the surrounding method is a static method (this is not accessible) or if this is never accessed in the current method. This property requires a live-variable analysis and cannot be decided in a peephole optimizer.
    3. Assume a (static) method that stores the values x,y, and z in local variables 0,1 and 2. Write down the code that the "naive" code generation scheme would generate for the expression x==y || x==z. Also write down the code that would be generated according to the "Jumping Code" code-generation scheme. How many instructions do both generated pieces of code execute in the case where "x==y" holds? solution

Maintained by Eric Bodden. [HOME]