COMPILER CONSTRUCTION Principles and practice Kenneth C. louden
COMPILER CONSTRUCTION Principles and Practice Kenneth C. Louden
7. Runtime environments PART ONE
7. Runtime Environments PART ONE
Contents Part One 7.1 Memory Organization during Program Execution 7.2 Fully Static Runtime Environments 7.3 Stack-Based runtime environments Part Two 7.4 Dynamic Memor 7.5 Parameter Passing Mechanisms 7.6 A Runtime Environment for the TINY Language
Contents Part One 7.1 Memory Organization During Program Execution 7.2 Fully Static Runtime Environments 7.3 Stack-Based Runtime Environments Part Two 7.4 Dynamic Memory 7.5 Parameter Passing Mechanisms 7.6 A Runtime Environment for the TINY Language
The precious chapters studied the phases of a compiler that perform static analysis of the source language Scanning, parsing, and static semantic analysis Depends only on the properties of the source language This chapter and the next turn to the task of studying how a compiler generates executable code Additional analysis such as that performed by an optimizer Some of this can be machine independent, but much of the task of code generation is dependent on the details of the target machine
• The precious chapters studied the phases of a compiler that perform static analysis of the source language – Scanning, parsing, and static semantic analysis – Depends only on the properties of the source language • This chapter and the next turn to the task of studying how a compiler generates executable code – Additional analysis, such as that performed by an optimizer – Some of this can be machine independent, but much of the task of code generation is dependent on the details of the target machine
Runtime environment The structure of the target computer's registers and memory that serves to manage memory and maintain the information needed to guide the execution process TThree kinds of runtime environments (1) Fully static environment; FORTRAN77 (2) Stack-Based environment; CC++ (3)Fully dynamic environment; LISP
• Runtime Environment The structure of the target computer’ s registers and memory that serves to manage memory and maintain the information needed to guide the execution process • Three kinds of runtime environments (1) Fully static environment; FORTRAN77 (2) Stack-Based environment; C C++ (3) Fully dynamic environment; LISP
Main issues will be discussed in more detail in the chapter For each environment, the language features and their properties Scoping and allocation issues; 2) Nature of procedure calls, B)Parameter passing mechanisms Focus on the general structure of the environment Note The compiler can only maintain an environment only indirectly It must generate code to perform the necessary maintenance operations during program execution
• Main issues will be discussed in more detail in the chapter: – For each environment, the language features and their properties (1) Scoping and allocation issues; (2) Nature of procedure calls; (3) Parameter passing mechanisms • Focus on the general structure of the environment • Note: – The compiler can only maintain an environment only indirectly – It must generate code to perform the necessary maintenance operations during program execution
7.1 Memory Organization During Program Execution
7.1 Memory Organization During Program Execution
The memory of a typical computer A register area Addressable Random access memory(ram) A code area a data area The code area is fixed prior to execution, and can be visualized as olle LOWS Entry pointer to procedure Code for procedure Entry pointer to procedure2 Code for procedure 2 Entry pointer to procedure n Code for procedure n In particular, the entry point for each procedure and function is known at compile time
The memory of a typical computer: A register area; Addressable Random access memory (RAM): A code area; A data area. The code area is fixed prior to execution, and can be visualized as follows: Entry pointer to procedure1→ Code for procedure 1 Entry pointer to procedure2→ Code for procedure 2 … Entry pointer to procedure n→ Code for procedure n In particular, the entry point for each procedure and function is known at compile time
The global and/or static data of a program can be fixed in memory prior to execution Data are allocated separately in a fixed area in a similar fashion to the code In Fortran 77.all data are in this class In Pascal, global variables are in this class In c. the external and static variables are in this class The constants are usually allocated memory in the global/static area Const declarations of c and pascal Literal values used in the code such as"Hello%Dn"and Integer value 12345 Printf(“Hllo%dn”,12345)
• The global and/or static data of a program can be fixed in memory prior to execution – Data are allocated separately in a fixed area in a similar fashion to the code • In Fortran77, all data are in this class; • In Pascal, global variables are in this class; • In C, the external and static variables are in this class • The constants are usually allocated memory in the global/static area – Const declarations of C and Pascal; – Literal values used in the code, • such as “Hello%D\n ” and Integer value 12345: • Printf(“Hello %d\n ”,12345);
The memory area used for dynamic data can be organized in many different ways Typically, this memory can be divided into a stack area and a heap area a stack area used for data whose allocation occurs in fifo fashion a heap area used for dynamic allocation occurs not in Fifo fashion Generally, the architecture of the target machine includes a processor stack for procedure calls and returns Sometimes, a compiler will have to arrange for the explicit allocation of the processor stack in an appropriate place in memory
• The memory area used for dynamic data can be organized in many different ways – Typically, this memory can be divided into a stack area and a heap area; • A stack area used for data whose allocation occurs in FIFO fashion; • A heap area used for dynamic allocation occurs not in FIFO fashion. • Generally, the architecture of the target machine includes a processor stack for procedure calls and returns. – Sometimes, a compiler will have to arrange for the explicit allocation of the processor stack in an appropriate place in memory