《编译原理》课程PPT教学课件(讲稿)第十章 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
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:

In a stack frame(activation record)we hold the following information 1)frame pointer: pointer value of the previous stack frame so we can reset the top of stack when we exit this function This is also sometimes called the dynamic link 2)static link: in languages(like Pascal but not C or Decaf) that allow nested function declarations, a function may be able to access the variables of the function(s )within which it is declared. In the static link, we hold the pointer value of the stack frame in which the current function was declared 3)return address: point in the code to which we return at the end of execution of the current function 4)values of arguments passed to the function and locals and temporaries used in the function
In a stack frame (activation record) we hold the following information: 1) frame pointer: pointer value of the previous stack frame so we can reset the top of stack when we exit this function. This is also sometimes called the dynamic link. 2) static link: in languages (like Pascal but not C or Decaf) that allow nested function declarations, a function may be able to access the variables of the function(s) within which it is declared. In the static link, we hold the pointer value of the stack frame in which the current function was declared. 3) return address: point in the code to which we return at the end of execution of the current function. 4) values of arguments passed to the function and locals and temporaries used in the function

Here is what typically happens when we call a function Before a function call, the calling routine saves any necessary registers During a function call, the target 2) pushes the arguments onto the routine stack for the target call saves any necessary registers 3)set up the static link(if 2)sets up the new frame pointer appropriate 3)makes space for any local 4) pushes the return address onto variables the stack 5)jumps to the target 4)does its work After a function call, the calling 5)tears down frame pointer and routine static link 1)removes return address and 7)restores any saved registers parameters from the stack 8)jumps to saved return address 2) restores any saved registers 3) continues executing
Here is what typically happens when we call a function Before a function call, the calling routine: 1) saves any necessary registers 2) pushes the arguments onto the stack for the target call 3) set up the static link (if appropriate) 4) pushes the return address onto the stack 5) jumps to the target After a function call, the calling routine: 1) removes return address and parameters from the stack 2) restores any saved registers 3) continues executing During a function call, the target routine: 1) saves any necessary registers 2) sets up the new frame pointer 3) makes space for any local variables 4) does its work 5) tears down frame pointer and static link 7) restores any saved registers 8) jumps to saved return address

Parameter passing Pass by value: This is the mechanism supported by C. value of parameters are copied into called routine Pass by reference: No copying is done, but a reference(usually implemented as a pointer)is given to the value. In addition to allowing the called routine to change the values, it is also efficient means for passing large variables(such as structs) Pass by value-result: This interesting variant supported by languages such as Ada copies the value of the parameter into the routine and then copies the (potentially changed) value back out. This has an effect similar to pass-by-reference, but not exactly Pass by name: This rather unusual mechanism acts somewhat likeC preprocessor macros and was introduced in algol. Rather than evaluating the parameter value, the name or expression is actually substituted into the calling sequence and each access to the parameter in the calling body re-evaulates it
Parameter passing Pass by value: This is the mechanism supported by C . Value of parameters are copied into called routine. Pass by reference: No copying is done, but a reference (usually implemented as a pointer) is given to the value. In addition to allowing the called routine to change the values, it is also efficient means for passing large variables (such as structs). Pass by value-result: This interesting variant supported by languages such as Ada copies the value of the parameter into the routine, and then copies the (potentially changed) value back out. This has an effect similar to pass-by-reference, but not exactly. Pass by name: This rather unusual mechanism acts somewhat like C preprocessor macros and was introduced in Algol. Rather than evaluating the parameter value, the name or expression is actually substituted into the calling sequence and each access to the parameter in the calling body re-evaulates it

Dynamic arrays a dynamic array is an array whose index bounds are not known until run-time. Dynamic arrays are found in Algol and Ada. In such languages, different dynamic arrays of the same type may have different index bounds. and therefore different numbers of elements How then can we make dynamic arrays satisfy the constant-size requirement? We are forced to adopt an indirect representation, in which the dynamic array's handle(also called an array descriptor or array information vector)contains not only a pointer to the array's elements but also the arrays index bounds The handle has a constant size
Dynamic arrays A dynamic array is an array whose index bounds are not known until run-time. Dynamic arrays are found in Algol and Ada. In such languages, different dynamic arrays of the same type may have different index bounds, and therefore different numbers of elements. How then can we make dynamic arrays satisfy the constant-size requirement? We are forced to adopt an indirect representation, in which the dynamic array’s handle (also called an array descriptor or array information vector) contains not only a pointer to the array’s elements but also the array’s index bounds. The handle has a constant size

Run-time organization for object-oriented languages Object-oriented (Oo) languages give rise to interesting and special problems in run-time organization An object is a special kind of record. Attached to each object are some methods, each method being a kind of procedure or function that is able to operate on that object. Objects are grouped into classes such that all objects of the same class have identical structure and identical methods
Run-time organization for object-oriented languages Object-oriented (OO) languages give rise to interesting and special problems in run-time organization. An object is a special kind of record. Attached to each object are some methods, each method being a kind of procedure or function that is able to operate on that object. Objects are grouped into classes, such that all objects of the same class have identical structure and identical methods
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《编译原理》课程PPT教学课件(讲稿)第十二章 代码生成.ppt
- 《编译原理》课程PPT教学课件(讲稿)第十一章 代码优化.ppt
- 《编译原理》课程PPT教学课件(讲稿)第六章 LR分析程序及其自动构造.ppt
- 《编译原理》课程PPT教学课件(讲稿)第八章 语法制导翻译和中间代码生成.ppt
- 《编译原理》课程PPT教学课件(讲稿)第五章 LL(1)文法及其分析程序.ppt
- 《编译原理》课程PPT教学课件(讲稿)第二章 PL/0编译程序.ppt
- 《编译原理》课程PPT教学课件(讲稿)第九章 符号表.ppt
- 《编译原理》课程PPT教学课件(讲稿)第三章 词法分析.ppt
- 《编译原理》课程PPT教学课件(讲稿)第一章 概述.ppt
- 华北电力大学《操作系统》PPT教案_第八章 文件系统(File System).ppt
- 华北电力大学《操作系统》PPT教案_第七章 设备管理 (Devices Management).ppt
- 华北电力大学《操作系统》PPT教案_第六章 虚拟存储器(Virtual Memory).ppt
- 华北电力大学《操作系统》PPT教案_第五课 存储器管理(Memory Management).ppt
- 华北电力大学《操作系统》PPT教案_第四章 调度和死锁(Scheduling and Deadlock).ppt
- 华北电力大学《操作系统》PPT教案_第三章 进程的同步和通讯 (Synchronization and Communication Among Processes).ppt
- 华北电力大学《操作系统》PPT教案_第二章 进程的描述和控制(Process Description and Control).ppt
- 华北电力大学《操作系统》PPT教案_第一章 操作系统概述.ppt
- 计算机硬件基本知识_鼠标.doc
- 计算机硬件基本知识_键盘.doc
- 计算机硬件基本知识_硬盘.doc
- 《编译原理》课程PPT教学课件(讲稿)第十章 目标程序运行时的组织.ppt
- 《编译原理》课程PPT教学课件(讲稿)第四章 文法和语言.ppt
- 《编译原理》课程PPT教学课件(讲稿)第四章 练习参考答案.ppt
- 《编译原理》课程PPT教学课件(讲稿)编译原理实验三、四讲稿.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)课程介绍.ppt
- 《VB语言程序设计》课程电子教案(讲义)教材习题答案(林卓然编著).doc
- 《VB语言程序设计》课程电子教案(PPT教学课件)第1章 认识 Visual Basic.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第2章 程序设计基础.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第3章 赋值与输入输出.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第4章 选择结构设计.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第5章 循环结构设计.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第6章 数组.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第7章 过程.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第8章 数据文件.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第9章 程序高度与错误处理.ppt
- 《VB语言程序设计》课程电子教案(PPT教学课件)第10章 其他常用的语句与控件.ppt
- 《VB语言程序设计》课程电子教案(讲义)教学安排.doc
- 《VB语言程序设计》课程电子教案(讲义)教学大纲.doc
- 《Flash MX基础培训教程》电子教案(PPT教学课件,上)第1章 Flash MX.ppt
- 《Flash MX基础培训教程》电子教案(PPT教学课件,上)第2章 创建矢量图形.ppt