山东大学编译原理Chapter7-Runtime Environments.pptVIP

  • 27
  • 0
  • 约2.41万字
  • 约 91页
  • 2016-12-07 发布于湖北
  • 举报

山东大学编译原理Chapter7-Runtime Environments.ppt

Chapter 7 Runtime Environments 一个程序要运行,至少应有这样两个存储空间: (1) 代码空间这是经翻译后生成的目标代码的存储区域,线性存放着目标指令序列。对三地址代码来说,当前执行的指令位置由指令指针ip指示。因此,只要将ip指向程序的第一个语句,程序便处于开始执行的状态,以后每执行一个语句,ip便加4(我们约定,三地址代码的每个语句占4个字节),指向下个语句。要改变程序控制顺序,只要将转向点赋给ip即可。 (2) 数据空间每个程序都定义一定数量的各种类型的变量和常数,翻译程序必须为之分配相应的存储空间。初等类型的数据,如逻辑、整型、实型变量,通常以存储器的基本存储单元如字节、字、双字来存储。 Chapter 7 Runtime Environments 7.1 Source Language Issues Program vs program execution A program consists of several procedures (functions) An execution of a program is called as a process An execution of a program would cause the activation of the related procedures A name (e.g, a variable name)in a procedure would be related to different data objects Notes: An activation may manipulate data objects allocated for its use. Chapter 7 Runtime Environments 7.1 Source Language Issues Allocation and de-allocation of data objects Managed by the run-time support package Allocation of a data object is just to allocate storage space to the data object relating to the name in the procedure Notes: The representation of a data object at run time is determined by its type. Chapter 7 Runtime Environments 7.1 Source Language Issues A procedure is activated when called The lifetime of an activation of a procedure is the sequence of steps between the first and last steps in the execution of the procedure body A procedure is recursive if a new activation can begin before an earlier activation of the same procedure has ended Chapter 7 Runtime Environments 7.1 Source Language Issues 3.Activation Trees A tree to depict the control flow enters and leaves activation of a procedure f(4) f(3) f(2) f(2) f(1) f(1) f(0) f(1) f(0) Procedure Activations: Example Activation Trees: Example Chapter 7 Runtime Environments 7.1 Source Language Issues 4.Control stacks A stack to keep track of live procedure activations Chapter 7 Runtime Environments 7.1 Source Language Issues Control Stack Scope R

文档评论(0)

1亿VIP精品文档

相关文档