2014compiler课件ch71new2008章节

上传人:w****i 文档编号:92189172 上传时间:2019-07-07 格式:PPT 页数:41 大小:516.50KB
返回 下载 相关 举报
2014compiler课件ch71new2008章节_第1页
第1页 / 共41页
2014compiler课件ch71new2008章节_第2页
第2页 / 共41页
2014compiler课件ch71new2008章节_第3页
第3页 / 共41页
2014compiler课件ch71new2008章节_第4页
第4页 / 共41页
2014compiler课件ch71new2008章节_第5页
第5页 / 共41页
点击查看更多>>
资源描述

《2014compiler课件ch71new2008章节》由会员分享,可在线阅读,更多相关《2014compiler课件ch71new2008章节(41页珍藏版)》请在金锄头文库上搜索。

1、Chapter 7,Runtime Environment Fully Static and Stack-Based Runtime Environments,Introduction,In previous chapter we have studied the phases of a compiler These stages depend only on the properties of the source language. are completely independent Of the target (machine or assembly) language The pro

2、perties of the target machine Operating system,Scanning Parsing Static semantic analysis,Last Stage,The last stage of compile process is the code generation . Much of this task is dependent on the details of the target machine. The general characteristics of the code generation remains the same acro

3、ss a wide variety of architectures.,Runtime Environment,Runtime Environment is the structure of the target computers registers and memory that serves to manage memory and maintain the information needed to guide the execution process. Three kinds of run time environment Fully static environment (FOR

4、TRAN77) Stack-based environment (C, C+, PASCAL) Fully dynamic environment (LISP) Hybrids of these are also possible.,Memory Organization,Memory,Register Area,Code Area RAM Data Area,In most compiled languages, it is not possible to make changes to the code area during execution. The code area is fix

5、ed prior to the execution, and all code addresses are computable at compile time.,Code Memory,Code for Procedure 1 Code for Procedure 2 . . Code for Procedure n,Entry point for procedure 1,Entry point for procedure 2,Entry point for procedure n,Entry point of each procedure and function is known at

6、compile time.,Data Area,Only a small part of data can be assigned fixed locations before execution begins Global and/or static data Compile-time constants Large integer values Floating-point values Literal strings,Dynamic Memory,The memory area for the allocation of dynamic data can be organized in

7、many different ways. A typical organization divides the dynamic memory into,stack area (LIFO protocol) heap area,code area global/static area stack free space heap,free space,Memory Organization,Procedure Activation Record,An important unit of memory Procedure activation record contains memory alloc

8、ated for the local data of a procedure or function when it is called, or activated.,arguments bookkeeping information (return address) local data local temporaries,The picture illustrates the general organization of an activation record. Details depend on the architecture of target machine and prope

9、rties of the language. When activation records are kept on stack, they are called stack frames.,Registers,Registers may be used to store temporaries, local variables, or even global variables. When a processor has many registers, the entire static area and whole activation records may be kept in the

10、 registers. Special purpose registers,Program counter (PC) Stack pointer (SP),Calling Sequence,The calling sequence is the sequence of operations that must occur when a procedure or function is called. Allocation of memory for the activation record The computation and storing the arguments Storing a

11、nd setting registers,Calling Sequence Design,Division of the calling sequence operations between the caller and the callee. Processor support versus generating explicit code for each step of calling sequence.,It is easier to generate calling sequence code at the point of call rather than inside the

12、callee. This causes the size of the code to grow.,Return Sequence,The return sequence is the sequence of operations needed when a procedure or function returns. The placing of the return value where it can be accessed by the caller Readjustment of registers Releasing of activation record memory,Full

13、y Static Runtime Environment,The simplest kind of a runtime environment. All data are static, remaining in memory for the duration of the program. All variables can be accessed directly via fixed addresses Each procedure has only a single activation record, which is allocated statically prior the ex

14、ecution. Such environment can be used to implement a language in which Example:,There are no pointers or dynamic allocation, Procedures cannot be called recursively.,FORTRAN77,Memory Organization (static runtime environment),code for main procedure code for procedure 1 . code for procedure n global

15、data area activation record of main procedure activation record of procedure 1 . activation record of procedure n,Code area,Data area,Example 1,PROGRAM TEST COMMON MAXSIZE INTEGER MAXSIZE REAL TABLE(10), TEMP MAXSIZE=10 READ *, TABLE(1), TABLE(2), TABLE(3) CALL QADMEAN(TABLE, 3, TEMP) PRINT *, TEMP

16、END,SUBROUTINE QUADMEAN(A, SIZE, QMEAN) COMMON MAXSIZE INTEGER MAXSIZE, SIZE REAL A(SIZE), QMEAN, TEMP INTEGER K TEMP = 0.0 IF (SIZE.GT.MAXSIZE).OR.)SIZE.LT.1) GOTO 99 DO 10 K=1,SIZE TEMP = TEMP +A(K)*A(K) 10 CONTINUE 99 QMEAN=SQRT(TEMP/SIZE) RETURN END,Example 1 Data Area,Global data area,Activation record of main,Activation record of QUADMEAN,Arrows indicate the values of the parameters,Stack-based Runtime Environment,In a language in which recurs

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号