The final exam will be cumulative. The breakdown of points will be approximately the following: 80-105 on material covered for Midterm 1, 80-105 on material covered for Midterm 2, and 50-80 on material covered since Midterm 2.

For sample questions for the material covered for Midterm 1 you should look at this page. For sample questions for the material covered for Midterm 2 you should look at this page.

Sample questions concerning material covered since Midterm 2:

  1. BRIEFLY define the following terms and give an example of how each term is used:
  2. Explain how a stack machine works for code generation and give examples of code generation for an arithmetic operator, an if statement and a function call. Make sure to discuss related issues (e.g., how is an AR represented). What is meant by the idea of maintaining stack discipline? (20)
  3. How is an AR created during code generation? Which parts of the code are responsible for generating the AR? Explain how the different parts of a function call interact during creation of the AR. (10)
  4. What is meant by the term stack discipline? How is it maintained and why is it important in a stack machine? (10)
  5. Assume you are in the process of writing a function cgen that does code generation for compiling a simple language to a stack machine represented in MIPS assembly. What would your cgen routine generate for an addition operator? (10)
  6. What is does the frame pointer in an AR do in a stack machine? Why is the frame pointer so important? How would the frame pointer be used in your code (give an example)? (10)
  7. How are objects represented in memory during code generation when inheritance occurs? What are the key issues for code generation and inheritance? (10)
  8. Explain how dynamic dispatch works for code containing objects with respect to inheritance. Give an example that illustrates your explanation. (10)
  9. Explain how value parameters and reference parameters are treated during code generation. What effects does this have on the code generation process? (10)
  10. One simple optimization that can be done in a stack machine is to maintain the temporaries needed for calculation in the AR rather than on the stack. What are the key questions in using this approach? Give an example of how you would go about defining the minimum number of temporaries needed and an example of how code generated would change under this approach. (15)
  11. Compilers often generate intermediate code from an AST rather than generating machine code? Why? Are there disadvantages to this approach? (10)
  12. Why is the term optimization something of a misnomer in compilers? What is optimized in the code? Define three different levels of optimization. (10)
  13. Define and give an example of the following types of local optimizations: (15)
    1. Algebraic simplification
    2. Constant folding
    3. Common sub-expression elimination
    4. Copy propagation
    5. Dead code elimination
  14. It is often the case that local optimizations are very simple. How then can they have such profound effects on code? Give an example to illustrate your point. (10)