Run-Time Environments CS308 Compiler Theory
Run-Time Environments CS308 Compiler Theory 1
Run-Time Environments How do we allocate the space for the generated target code and the data object of our source programs? The places of the data objects that can be determined at compile time will be allocated statically. But the places for the some of data objects will be allocated at run-time. The allocation of de-allocation of the data objects is managed by the run-time support package. run-time support package is loaded together with the generate target code. the structure of the run-time support package depends on the semantics of the programming language (especially the semantics of procedures in that language). Each execution of a procedure is called as activation of that procedure. CS308 Compiler Theory 2
Run-Time Environments • How do we allocate the space for the generated target code and the data obj f ect o f our source programs? • The places of the data objects that can be determined at compile time will be all t d t ti ll lloca t e d s t atically. • But the places for the some of data objects will be allocated at run-time. • Th ll ti f d The allocation o f de-all ti f th d t bj t i d b th llocation o f the d a ta objec ts is manage d by the run-time support package. – run -time support package is loaded together with the generate target code time support package is loaded together with the generate target code. – the structure of the run-time support package depends on the semantics of the programming language (especially the semantics of procedures in that language). • E h i f d i ll d Eac h execut ion o f a proce dure is call e d as activation ofh d t at proce dure. CS308 Compiler Theory 2
Procedure Activations An execution of a procedure starts at the beginning of the procedure body; When the procedure is completed,it returns the control to the point immediately after the place where that procedure is called Each execution of a procedure is called as its activation. Lifetime of an activation of a procedure is the sequence of the steps between the first and the last steps in the execution of that procedure (including the other procedures called by that procedure). If a and b are procedure activations,then their lifetimes are either non- overlapping or are nested. If a procedure is recursive,a new activation can begin before an earlier activation of the same procedure has ended. CS308 Compiler Theory 3
Procedure Activations • An execution of a procedure starts at the beginning of the procedure b do dy; • When the procedure is completed, it returns the control to the point i di t l ft th l h th t d i ll d immedi a t e ly after the p lace w here th a t proce dure is call e d. • Each execution of a procedure is called as its activation. • Lif i et ime of ti ti f d i th f th t f an activation o f a proce dure is the sequence o f the s teps between the first and the last steps in the execution of that procedure (including the other procedures called by that procedure) (including the other procedures called by that procedure). • If a and b are procedure activations, then their lifetimes are either nonoverlapping rlappin g or are nested. • If a procedure is recursive, a new activation can begin before an earlier activation of the same procedure has ended. CS308 Compiler Theory 3
Activation tree We can use a tree (called activation tree)to show the way control enters and leaves activations. In an activation tree: -Each node represents an activation of a procedure. The root represents the activation of the main program. The node a is a parent of the node b iff the control flows from a to b. -The node a is left toto the node b iff the lifetime of a occurs before the lifetime of b. CS308 Compiler Theory 4
Activation Tree • We can use a tree (called activation tree) to show the way control enters andl i i eaves activations. • In an activation tree: – Each node represents an activation of a procedure. – The root represents the activation of the main program. – The node a is a parent of the node b iff the control flows from a to b. – The node a is left to to the node b iff the lifetime of a occurs before the lifetime of b. CS308 Compiler Theory 4
Activation Tree (cont.) program main; enter main procedure s; enter p begin ..end; enter q procedure p; _exit q procedure q; Center s begin ..end; -exit s begin q;s;end; exit p begin p;s;end; enter s -exit s exit main A Nested Structure CS308 Compiler Theory
Activation Tree (cont.) program main; enter main procedure s; enter p begin ... end; enter q proce dure p; exit q procedure q; enter s begin end; begin ... end; exit s begin q; s; end; exit p begin p; s; end; begin p; s; end; enter s enter s exit s exit main A Nested Structure CS308 Compiler Theory 5