Docsity

run time environment ppt-lecture notes, Lecture notes of Compiler Design

Partial preview of the text

Download run time environment ppt-lecture notes and more Lecture notes Compiler Design in PDF only on Docsity!

Run-Time Environments

- How allocation & de-allocation of data

objects is done : at compile time &

runtime

Source Language Issues

• Procedures

• Activation trees

• Control stacks

• Scope of a declaration

• Binding of names

Program for Quick sort

Activation Trees

  • (^) We make the following assumptions about the flow of control among procedures during execution of a program:
    1. Control flows sequentially.
    2. Each execution of a procedure starts at the beginning of the procedure and eventually returns control to the point immediately following the place where the procedure was called.
  • (^) Each execution of a procedure is called Activation of the procedure.
  • (^) In an activation tree,
    1. Each node represents an activation of a procedure.
    2. The root represents the activation of the main program.
    3. The node for a is the parent of the node for b if and only if control flows from activation a to b.
    4. The node for a is to the left of the node for b if and only if the lifetime of a occurs before the lifetime of b.
  • (^) At this point the control stack contains the following nodes along this path to the root: s, q(1,9), q(1,3), q(2,3) and no other nodes.
  • (^) The portion of the program to which a declaration applies is called the Scope of that declaration.
  • (^) An occurrence of a name in a procedure is said to be local to the procedure if it is in the scope of a declaration within the procedure, otherwise, the occurrence is said to be nonlocal.
  • (^) At compile time, the symbol table can be used to find the declaration that applies to an occurrence of a name. When a declaration is seen, a symbol table entry is created for it.
  • (^) As long as we are in the scope of the declaration, its entry is returned when the name in it is looked up.
  • (^) Environment and States are different; an assignment changes the state, but not the environment.
  • (^) When an environment associates storage location s with a name x, we say that x is bound to s; the association itself is referred to as binding of x.

Static and Dynamic Notions of Bindings

  • (^) It is customary to push the activation record on the run-time stack when the procedure is called and to pop the activation record off the stack when control returns to the caller.
  • (^) The purpose of fields of activation record:
    1. Temporary values , such as those arising in the evaluation of expressions, are stored in the field for temporaries.
    2. The field for Local data holds data that is local to an execution of a procedure.
    3. The field for Saved machine status holds information about the state of the machine just before the procedure is called. This information includes the values of the program counter and machine registers that have to be restored when control returns from the procedure.
  1. The optional Access link is used to refer to nonlocal data held in other activation records.
  2. The optional Control link points to the activation record of the caller.
  3. The field for Actual parameters is used by the calling procedure to supply parameters to the called procedure.
  4. The field for the Returned value is used by the called procedure to return a value to the calling procedure.