编译运行环境

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

– Fully dynamic environment
Compiling and Running of Program
-8-
Knowledge Relation Graph
Information Science and Technology College of Northeast Normal University
Compiling and Running of Program
-12-
Information Science and Technology College of Northeast Normal University
Memory Organization
Heap(堆区)
Dynamic allocated
-6-
Information Science and Technology College of Northeast Normal University
Main Content of Chapter 9
§9. Runtime Environment(运行时存储环境)
– 9.1 Storage Organization & Allocation (存储结构和分配) – 9.2 Activation Record & Stack(活动记录和栈) – 9.3 Variable Access Environment(变量访问环境)
Compiling and Running of Program
-10-
Information Science and Technology College of Northeast Normal University
General Memory Organization
Compiling and Running of Program
Compiling and Running of Program
Stack(栈区)
Static area (静态区) Code area (代码区)
Memory
Compiling and Running of Program
Local space for functions
Static/global Target codes; Library code;
-13-
假设有变量说明: VAR A:ARRAY [1..5] [1..5] OF INTEGER; i, j, t:INTEGER; 将下述程序段翻译成四元式序列: i:=5; j:=1; WHILE j<=5 DO BEGIN IF (j<=3) THEN t:= 1 ELSE t:=0; A[i][j]:= t; j:=j+1; END;
• Why?
– Need to understand the execution mechanism of a program;
– For the purpose of target code generation;
• How?
Who?
– Fully static environment
– Stack-based environment ※
了解程序运行时内存结构 从而在目标代码中实现
why
Runtime how 在目标代码中
Environment
体现这些机制
what
静态区分配 堆区分配
(1)运行时内存的组织结构; (2)内存空间分配; (3)抽象地址的具体化;
Fully static Fully dynamic Stack based
ELSE t:=0; A[i][j]:= t; j:=j+1; END;
-3-
Information Science and Technology College of Northeast Normal University
Lexical Analysis scanning
Syntax Analysis Parsing
Information Science and Technology College of Northeast Normal University
Compiling and Running of Program
Compiling and Running of Program
-1-
Information Science and Technology College of Northeast Normal University
const int n=5; int sum = 0; Information Science and Technology College of
Northeast Normal University
int square(int i) { int j;
j = i*i; return (j);}
void main () { int j; j = square(n); sum = sum+j; }
Semantic Analysis
analysis/front end
Compiling and Running of Program
Where we are?
Target Code
Generation

行Leabharlann Baidu

Intermediate Code Optimization



Intermediate Code

Generation
synthesis/back end
-4-
Information Science and Technology College of Northeast Normal University
From Intermediate Code to Target Code
源 程 序
翻译过程特点: (1)执行过程的直译
-11-
Information Science and Technology College of Northeast Normal University
运行时存储空间的划分
依据:程序=算法+数据结构
一个目标程序运行时所需要的存储空间包括:
• 存放目标代码的空间 • 存放数据项目的空间 • 存放程序运行的控制或连接数据所需单元 Alan J.Perlis: To understand a program you must become both the machine and the program.
Information Science and Technology College of Northeast Normal University
Main idea:
All data are static, remaining fixed in memory during program execution;
• Memory organization during program execution • Different Programming Languages will adopt
different runtime environment
– Fully Static Runtime Environment (FORTRAN77) – Stack-based Runtime Environment (PASCAL, C) – Fully Dynamic Runtime Environment (LISP)
(+, sum, j, t2) (assign, t2, _, sum) (ENDFUN, _, _, _)
Stack: square() main()
global variables target codes
runtime environment (memory)
Compiling and Running of Program
Information Science and Technology College of Northeast Normal University
Fully Static Memory Organization
Compiling and Running of Program
-14-
Fully Static Runtime Environment




代 翻译过程特点:

码 (1)执行过程的具体全 码
;
部实现;
(2)采用抽象地址;
(2)采用具体地址;
(3)需要考虑运行时存
储空间问题;
(4) 函数返回地址;
Compiling and Running of Program
-5-
Demonstration of Sample Program Execution
栈区分配
变量访问环境
Compiling and Running of Program
-9-
Information Science and Technology College of Northeast Normal University
9.1 Storage Organization & Allocation
Compiling and Running of Program
-2-
Information Science and Technology College of
Northeast Nor(mAalSUSnIiGve,rs5i,ty_ , i ) (ASSIG, 1, _ , j ) (lable, WHILE) (<= , j , 5 , t1) (Jump0, t1, ENDWHILE) (<= , j , 3 , t2 ) (Jump0,t2,ELSE ) (ASSIG, 1, _ , t ) (Jump, ENDIF) (lable,ELSE) (ASSIG, 0, _ , t ) (ENDIF, _ , _ , _ ) (ASSIG, Size (INTEGER), _, size) (SUBI, i, 1, t3) (MULTI, t3, 5, t4) (MULTI, t4, size, t5) (ADDI, Addr(A), t5, t6) (SUBI, j, 1, t7) (MULTI, t7, 1, t8) (MULTI, t8, size, t9) (ADDI, t6, t9 t10) (ASSIG, t, _, t10) (+, j , 1 ,t11) (ASSIG, t11, _ , j) (Lable,ENDWHILE)
Requirements on Programming Languages:
No pointer;
No dynamic allocation;
Procedures cannot be called recursively;
Static area (静态区)
Code area (代码区) Memory Organization
(assign, 0, _, sum) (ENTRY, L1, 3 , 0) (*, i, i, t1) (assig, t1, _, j) (RETURN, _, _, j) (ENDFUN, _, _, _)
(ENTRY, L2, 2 , 0)
(VALACT, n, 0, 1)
(call, square, true, j)
Compiling and Running of Program
假设有变量说明: VAR A:ARRAY [1..5] [1..5] OF
INTEGER; i, j, t:INTEGER; 将下述程序段翻译成四元式序
列: i:=5; j:=1; WHILE j<=5 DO BEGIN IF (j<=3) THEN t:= 1
Compiling and Running of Program
-7-
About “Runtime Environment”
• What?
Information Science and Technology College of Northeast Normal University
– The structure of the target computer’s register and memory that servers to manage memory and maintain information needed to guide the execution process.
相关文档
最新文档