Saving Registers during CallsTopAnouncementsGenerating Code for Methods

Generating Code for Methods

  1. There are several issues to consider to prepare to generate code for methods:

    1. What runtime structures are involved in the invocation of a method.

    2. How to handle parameters.

    3. How to handle return values.

    4. What the basic method header and trailer code looks like.

      • Using the chain of static link pointers
      • saving return information

      • Saving and restoring registers.

    5. When to generate code for each method while traversing the syntax tree.

  2. Recall the basic 34000 call and return sequences:

  3. This depends on (and results in) the following frame structure:

  4. The handling of method parameters in your compiler will reflect simple, but outdated technology. The most glaring simplification/inefficiency will be the use of memory rather than registers to pass parameters and other information between caller and callee.

  5. Handling return values can be approached in one of two ways: Saving the result on the stack will prove simpler. This means:

  6. In addition, we will assume that A5 holds a pointer to the object associated with the currently executing method.

  7. A very fundamental difference between the standard calling sequence and the code you must generate is that you cannot produce JSR instructions that statically specify the name of the target method's first instruction.

  8. As a result, in place of a single JSR instruction, you will have to generate: or, you can build a table of branches to the methods instead of just a table of their address and then generate: Since the 34000 doens't do any sophisticated pipelining or branch prediction, the second method will be best.

  9. When to generate code (or the beauty of using the assembler): The nice thing about using the assembler is how flexibly you can change the order of things. If you prefer to have all the method tables before all the code, you can easily arrange that too!

  10. Another difference between method calls in Woolite and the standard 68000/34000 call sequence is the need to deal with the object pointer (A5).
  11. About that chain of static links....

Computer Science 434
Department of Computer Science
Williams College

Saving Registers during CallsTopAnouncementsGenerating Code for Methods