RUN-Time Organization Compiler phase Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions, storage, and system software) in order to implement the source language. This is called run-time organization
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions, storage, and system software) in order to implement the source language. This is called run-time organization
The key issues in run-time organization Data representation how should we represent the values of each source-language type in the target machine? Expression evaluation: How should we organize the evaluation of expressions, taking care of intermediate results? I Storage allocation How should we organize storage for variables, taking into account the different lifetimes of global, local and heap variables? I Routines: How should we implement procedures, functions and parameters in terms of low-level routines? Run-time organization for object-oriented languages: How should we represent objects and methods?
The key issues in run-time organization l Data representation: How should we represent the values of each source-language type in the target machine? Expression evaluation: How should we organize the evaluation of expressions, taking care of intermediate results? l Storage allocation: How should we organize storage for variables, taking into account the different lifetimes of global, local and heap variables? l Routines: How should we implement procedures, functions, and parameters, in terms of low-level routines? Run-time organization for object-oriented languages: How should we represent objects and methods?
Storage classes global: exist throughout lifetime of entire program and can e referenced anywhere static:exist throughout lifetime of entire program but can only be referenced in the function(or module)in which the ey are declare local: (also called automatic) exist only for the duration of a call to the routine in which they are declared; a new variable is created each time the routine is entered(and destroyed on exit) dynamic: variables that are created during program execution;usually represented by an address held in a variable of one of the above classes
Storage classes global: exist throughout lifetime of entire program and can be referenced anywhere. static: exist throughout lifetime of entire program but can only be referenced in the function (or module) in which they are declared. local: (also called automatic) exist only for the duration of a call to the routine in which they are declared; a new variable is created each time the routine is entered (and destroyed on exit). dynamic: variables that are created during program execution; usually represented by an address held in a variable of one of the above classes
Both global and static variables have a single instance that persists throughout life of program and the usual implementation for these is a collection of memory locations in the global/static data segment of the executable. These locations are fixed at the end of the compilation process Local variables only come into existence on entry to a routine and persist until its exit. To handle these we use a runtime stack that holds the values of locals. The area of memory used to hold all the locals of a routine is called the stack frame(active record). The stack frame for the routine currently executing will be on top of the stack Dynamic allocation of further storage during the run of a program is done by calling library functions(e.g, malloch). This storage is obtained from memory in a different segment than the program code global/static, or stack. Such memory is called the heap
Both global and static variables have a single instance that persists throughout life of program and the usual implementation for these is a collection of memory locations in the global/static data segment of the executable. These locations are fixed at the end of the compilation process. Local variables only come into existence on entry to a routine and persist until its exit. To handle these we use a runtime stack that holds the values of locals. The area of memory used to hold all the locals of a routine is called the stack frame(active record). The stack frame for the routine currently executing will be on top of the stack. Dynamic allocation of further storage during the run of a program is done by calling library functions (e.g., malloc()). This storage is obtained from memory in a different segment than the program code, global/static, or stack. Such memory is called the heap
Heres a map depicting the address space of an executing program Stack Heap Global/static data Code
Here’s a map depicting the address space of an executing program: