The document discusses a lecture on compiler design presented by Dr. Ioanna Dionysiou. The lecture covers intermediate code representation, specifically 3-address code, as well as run-time environments. It provides outlines of the topics to be discussed, including the essentials of 3-address code and implementation techniques. It also discusses source language issues like activation trees, control stacks, scope of declarations and bindings. Finally, it discusses storage organization using activation records and different storage allocation strategies like static, stack and heap allocation.
Gurukul Skills Schedule for the Month of March
Time Cohort-10 Cohort-11 Cohort-12
8.00 to 09.25 Revision Revision Revision
5 Minutes Short Break
9.30 to 11.30 Chartered Accountants Chartered Accountants ENGLISH/SOFT SKILLS
15 Minutes Short Break
11.45 to 01.45 ICT ENGLISH/SOFT SKILLS R&A
45 Minutues Lunch Break
2.30 to 04.30 ENGLISH/SOFT SKILLS R&A ICT
15 Minutes Short Break
4.45 to 06.30 R&A ICT ACCOUNTS
5 Minutes Short Break
6.35 to 08.00 Assingments Assingments Assingments
This document discusses runtime environments and storage allocation strategies. It covers:
- How procedure activations are represented at runtime using activation records, control stacks, and activation trees. Activation records store local variables, parameters, return values, and more.
- Different strategies for allocating storage at runtime, including static allocation where sizes are known at compile time, stack allocation for procedure activations and recursion, and heap allocation for dynamic memory.
- How names are bound to values at compile time through environments and at runtime through states. The scope and lifetime of bindings are also discussed.
- Issues related to mapping names to storage locations and values at runtime, including how assignments change the state but not the environment.
-
The document discusses procedure activations and lifetimes. It provides an example of an activation tree for a quicksort program, showing the nested calls to procedures like partition and quicksort. It describes how activation records are used to store state and pass parameters during procedure calls, including the use of control links and access links to manage nested procedures and nonlocal data.
Iterators in Python allow iteration over iterable objects like lists, tuples, dicts and sets. An iterator is initialized using the iter() method and iterates using the next() method. For loops internally use iter() and next() to iterate. Custom iterators can also be defined by implementing the __iter__() and __next__() methods. Some key differences between recursion and iteration are that recursion involves function calls while iteration uses loops, and recursion has greater overhead. Common algorithms like factorial, Fibonacci sequence and Tower of Hanoi can be implemented using both recursion and iteration.
1. The document outlines an agenda for a lesson on Python programming language. It includes warm-up exercises, presentations, videos, practical coding exercises for students in pairs, questions and answers, reflection, and homework assignment.
2. The core content of the lesson involves a teacher presentation on Python basics using PowerPoint, a video about Python, and hands-on coding practice where students work in pairs to create simple Python programs using various online or offline platforms like Anaconda and Spyder.
3. For homework, students are asked to create a presentation on concepts of repetition and selection in Python programming based on a provided rubric.
Learning Outcome: 1- Gain knowledge and understanding the meaning of computer language? 2- Draw conclusions about concepts: data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
Key Concepts: 1- Concept of computer language. 2- Concept of different data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
Skills: At the completion of the program, students should be able to: 1- understand the structure of the program. 2- Design some programs include different data types, variables, Conditional statements and looping statements. 3- Compile the program (Run).
Essential Questions: 1- What is meant by programming language and give some examples? 2- What are the key features or characteristics of language? Textbook and Resource Materials: https://www.w3schools.com
Evidence of Learning: Create a presentation contains some concepts of computer languages and display the Concepts of different data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
SEC Topic & Code: Using appropriate programming language to produce a project that solves societal or learning problem creatively
The document discusses run-time environments and how compilers support program execution through run-time environments. It covers:
1) The compiler cooperates with the OS and system software through a run-time environment to implement language abstractions during execution.
2) The run-time environment handles storage layout/allocation, variable access, procedure linkage, parameter passing and interfacing with the OS.
3) Memory is typically divided into code, static storage, heap and stack areas, with the stack and heap growing towards opposite ends of memory dynamically during execution.
Gurukul Skills Schedule for the Month of March
Time Cohort-10 Cohort-11 Cohort-12
8.00 to 09.25 Revision Revision Revision
5 Minutes Short Break
9.30 to 11.30 Chartered Accountants Chartered Accountants ENGLISH/SOFT SKILLS
15 Minutes Short Break
11.45 to 01.45 ICT ENGLISH/SOFT SKILLS R&A
45 Minutues Lunch Break
2.30 to 04.30 ENGLISH/SOFT SKILLS R&A ICT
15 Minutes Short Break
4.45 to 06.30 R&A ICT ACCOUNTS
5 Minutes Short Break
6.35 to 08.00 Assingments Assingments Assingments
This document discusses runtime environments and storage allocation strategies. It covers:
- How procedure activations are represented at runtime using activation records, control stacks, and activation trees. Activation records store local variables, parameters, return values, and more.
- Different strategies for allocating storage at runtime, including static allocation where sizes are known at compile time, stack allocation for procedure activations and recursion, and heap allocation for dynamic memory.
- How names are bound to values at compile time through environments and at runtime through states. The scope and lifetime of bindings are also discussed.
- Issues related to mapping names to storage locations and values at runtime, including how assignments change the state but not the environment.
-
The document discusses procedure activations and lifetimes. It provides an example of an activation tree for a quicksort program, showing the nested calls to procedures like partition and quicksort. It describes how activation records are used to store state and pass parameters during procedure calls, including the use of control links and access links to manage nested procedures and nonlocal data.
Iterators in Python allow iteration over iterable objects like lists, tuples, dicts and sets. An iterator is initialized using the iter() method and iterates using the next() method. For loops internally use iter() and next() to iterate. Custom iterators can also be defined by implementing the __iter__() and __next__() methods. Some key differences between recursion and iteration are that recursion involves function calls while iteration uses loops, and recursion has greater overhead. Common algorithms like factorial, Fibonacci sequence and Tower of Hanoi can be implemented using both recursion and iteration.
1. The document outlines an agenda for a lesson on Python programming language. It includes warm-up exercises, presentations, videos, practical coding exercises for students in pairs, questions and answers, reflection, and homework assignment.
2. The core content of the lesson involves a teacher presentation on Python basics using PowerPoint, a video about Python, and hands-on coding practice where students work in pairs to create simple Python programs using various online or offline platforms like Anaconda and Spyder.
3. For homework, students are asked to create a presentation on concepts of repetition and selection in Python programming based on a provided rubric.
Learning Outcome: 1- Gain knowledge and understanding the meaning of computer language? 2- Draw conclusions about concepts: data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
Key Concepts: 1- Concept of computer language. 2- Concept of different data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
Skills: At the completion of the program, students should be able to: 1- understand the structure of the program. 2- Design some programs include different data types, variables, Conditional statements and looping statements. 3- Compile the program (Run).
Essential Questions: 1- What is meant by programming language and give some examples? 2- What are the key features or characteristics of language? Textbook and Resource Materials: https://www.w3schools.com
Evidence of Learning: Create a presentation contains some concepts of computer languages and display the Concepts of different data types, variables, Conditional statements, looping statements, functions and Object Oriented Programming.
SEC Topic & Code: Using appropriate programming language to produce a project that solves societal or learning problem creatively
The document discusses run-time environments and how compilers support program execution through run-time environments. It covers:
1) The compiler cooperates with the OS and system software through a run-time environment to implement language abstractions during execution.
2) The run-time environment handles storage layout/allocation, variable access, procedure linkage, parameter passing and interfacing with the OS.
3) Memory is typically divided into code, static storage, heap and stack areas, with the stack and heap growing towards opposite ends of memory dynamically during execution.
The document discusses Java's console input and how to read input from the keyboard using the Scanner class. It provides steps to construct a Scanner object, import the Scanner class, and use various Scanner methods like nextDouble() and nextInt() to read floating point numbers and integers from keyboard input. The document also briefly covers do-while and switch statements in Java.
02 functions, variables, basic input and output of c++Manzoor ALam
This document discusses computer programming functions, variables, and basic input/output in C and C++. It covers:
- Defining and calling functions, function parameters and return values.
- Declaring and assigning values to variables of different data types like int, float, and double.
- Using basic input/output functions like cout and cin to display output and get user input.
- The scope of variables and how they work within and outside of functions.
This document discusses run-time environments and compiler design. It describes how run-time support packages manage allocation and deallocation of data objects and determine data representation based on type. It also explains activation trees which depict the flow of control among procedures during program execution, with each node representing a procedure activation and the relationships between nodes showing how control passes from one activation to another. An example Pascal program for sorting integers is provided to illustrate procedure activations.
Java 8 includes new functional features such as lambda expressions, method references, and streams. Lambda expressions allow for the creation of anonymous functions, and method references provide a way to refer to existing methods. Streams facilitate functional-style aggregate operations on data and support both sequential and parallel operations. Other features include default interface methods, closures, and static methods on interfaces.
The document discusses Python programming language. It provides an introduction to Python, describing it as an interpreted, high-level and general-purpose programming language. It then covers various data types in Python including numbers, strings, booleans, lists, tuples, sets and dictionaries. The document also discusses operators in Python like arithmetic, comparison, logical and bitwise operators. Finally, it explains how to work with Python in both interactive and script modes.
Workshop "Can my .NET application use less CPU / RAM?", Yevhen TatarynovFwdays
In most cases it’s very hard to predict the number of resources needed for your .NET application. But If you spot some abnormal CPU or RAM usage, how to answer the question “Can my application use less?”.
Let’s see samples from real projects, where optimal resource usage by the application became one of the values for the product owner and see how less resource consumption can be.
The workshop will be actual for .NET developers who are interested in optimization of .NET applications, QA engineers who involved performance testing of .NET applications. It also will be interesting to everyone who "suspected" their .NET applications of non-optimal use of resources, but for some reason did not start an investigation.
This document provides an overview of the Python programming language. It discusses Python's history, features, and why it is a good programming language. Key points covered include:
- Python was created in the late 1980s and draws from many other languages.
- It is an open source, interpreted, object-oriented, and portable language with a large online community and library support.
- Python code is compiled to bytecode for performance. It has dynamic typing, automatic memory management, and is powerful yet easy to learn.
- The document reviews Python statements, expressions, variables, basic data types, functions, modules and exceptions. It provides examples of Python code.
This document provides information about the Python programming language. It discusses the features of Python, including that it is object-oriented, open source, portable, powerful, and easy to learn. It also covers Python syntax, statements, functions, modules, exception handling, and how to run Python programs. The outcomes of learning these Python concepts are also listed.
This document discusses algorithm analysis tools. It explains that algorithm analysis is used to determine which of several algorithms to solve a problem is most efficient. Theoretical analysis counts primitive operations to approximate runtime as a function of input size. Common complexity classes like constant, linear, quadratic, and exponential time are defined based on how quickly runtime grows with size. Big-O notation represents the asymptotic upper bound of a function's growth rate to classify algorithms.
Chapter 1 Class 12 Computer Science Unit 1ssusera7a08a
The document discusses the basics of Python programming language. It provides an introduction to Python, describing how it is an interpreted, high-level and general-purpose programming language. It then covers Python features, data types, operators, and how to work in both interactive and script modes in Python. The document also discusses topics like variables, data handling, arithmetic operators, comparison operators, and more with examples.
This document summarizes an integrated control system design tool that was developed to analyze and design intelligent control systems. The tool allows users to:
- Build interactive CAD models for control system design
- Incorporate various libraries and integrate popular AI techniques
- Simulate systems using mixed continuous/discrete event simulation
- Represent systems with generalized Petri net and fuzzy system models
- Program using a new matrix-based language
- Model dead time elements flexibly
- Apply the tool to examples like adaptive fuzzy PID control and liquid level control
The document outlines the goals, background, achievements, related tools, and plans for future work regarding the development of the integrated intelligent control system design tool.
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
Problem solving using computers involves transforming a problem description into a solution using problem-solving strategies, techniques, and tools. Programming is a problem-solving activity where instructions are written for a computer to solve something. The document then discusses the steps in problem solving like definition, analysis, approach, coding, testing etc. It provides examples of algorithms, flowcharts, pseudocode and discusses concepts like top-down design, time complexity, space complexity and ways to swap variables and count values.
The document provides an introduction and recap of data structures and algorithms concepts. It discusses different data structures like arrays, linked lists, stacks, queues, trees and graphs. It summarizes the time complexities of common operations on these data structures. It also introduces recursion as a programming technique, explaining the general structure of recursive functions and how function calls use the program stack.
This document provides an introduction to R for econometrics. It covers installing R and RStudio, the basics of R including expressions, variables, functions, modules and packages. It demonstrates some key features of R through examples and discusses why R is popular for data analysis and science. Flow control structures like if/else, while and for loops are also introduced. Additional appendices provide more details on objects, operators, sampling, common functions and basic graphics in R.
This document provides an introduction to R for econometric analysis. It discusses installing R and RStudio, why R is useful for data science and analysis tasks, basic R syntax like variables, functions, modules and packages. It also demonstrates some R code examples and covers flow control, objects, operators, sampling, common functions and basic graphics. The document is intended to give students a quick start in learning the R programming language.
The document summarizes computational aspects of vehicle routing problems. It discusses time complexity and space complexity, and how they are measured as functions of problem size. It provides examples of calculating complexity for different algorithms. It also discusses common data structures for representing routes, including array lists, doubly linked lists, and their pros and cons for different operations. The document outlines Java code examples for comparing route representation using these data structures.
In this presentation we introduce a family of gossiping algorithms whose members share the same structure though they vary their performance in function of a combinatorial parameter. We show that such parameter may be considered as a “knob” controlling the amount of communication parallelism characterizing the algorithms. After this we introduce procedures to operate the knob and choose parameters matching the amount of communication channels currently provided by the available communication system(s). In so doing we provide a robust mechanism to tune the production of requests for communication after the current operational conditions of the consumers of such requests. This can be used to achieve high performance and programmatic avoidance of undesirable events such as message collisions.
Paper available at https://dl.dropboxusercontent.com/u/67040428/Articles/pdp12.pdf
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
The document discusses Java's console input and how to read input from the keyboard using the Scanner class. It provides steps to construct a Scanner object, import the Scanner class, and use various Scanner methods like nextDouble() and nextInt() to read floating point numbers and integers from keyboard input. The document also briefly covers do-while and switch statements in Java.
02 functions, variables, basic input and output of c++Manzoor ALam
This document discusses computer programming functions, variables, and basic input/output in C and C++. It covers:
- Defining and calling functions, function parameters and return values.
- Declaring and assigning values to variables of different data types like int, float, and double.
- Using basic input/output functions like cout and cin to display output and get user input.
- The scope of variables and how they work within and outside of functions.
This document discusses run-time environments and compiler design. It describes how run-time support packages manage allocation and deallocation of data objects and determine data representation based on type. It also explains activation trees which depict the flow of control among procedures during program execution, with each node representing a procedure activation and the relationships between nodes showing how control passes from one activation to another. An example Pascal program for sorting integers is provided to illustrate procedure activations.
Java 8 includes new functional features such as lambda expressions, method references, and streams. Lambda expressions allow for the creation of anonymous functions, and method references provide a way to refer to existing methods. Streams facilitate functional-style aggregate operations on data and support both sequential and parallel operations. Other features include default interface methods, closures, and static methods on interfaces.
The document discusses Python programming language. It provides an introduction to Python, describing it as an interpreted, high-level and general-purpose programming language. It then covers various data types in Python including numbers, strings, booleans, lists, tuples, sets and dictionaries. The document also discusses operators in Python like arithmetic, comparison, logical and bitwise operators. Finally, it explains how to work with Python in both interactive and script modes.
Workshop "Can my .NET application use less CPU / RAM?", Yevhen TatarynovFwdays
In most cases it’s very hard to predict the number of resources needed for your .NET application. But If you spot some abnormal CPU or RAM usage, how to answer the question “Can my application use less?”.
Let’s see samples from real projects, where optimal resource usage by the application became one of the values for the product owner and see how less resource consumption can be.
The workshop will be actual for .NET developers who are interested in optimization of .NET applications, QA engineers who involved performance testing of .NET applications. It also will be interesting to everyone who "suspected" their .NET applications of non-optimal use of resources, but for some reason did not start an investigation.
This document provides an overview of the Python programming language. It discusses Python's history, features, and why it is a good programming language. Key points covered include:
- Python was created in the late 1980s and draws from many other languages.
- It is an open source, interpreted, object-oriented, and portable language with a large online community and library support.
- Python code is compiled to bytecode for performance. It has dynamic typing, automatic memory management, and is powerful yet easy to learn.
- The document reviews Python statements, expressions, variables, basic data types, functions, modules and exceptions. It provides examples of Python code.
This document provides information about the Python programming language. It discusses the features of Python, including that it is object-oriented, open source, portable, powerful, and easy to learn. It also covers Python syntax, statements, functions, modules, exception handling, and how to run Python programs. The outcomes of learning these Python concepts are also listed.
This document discusses algorithm analysis tools. It explains that algorithm analysis is used to determine which of several algorithms to solve a problem is most efficient. Theoretical analysis counts primitive operations to approximate runtime as a function of input size. Common complexity classes like constant, linear, quadratic, and exponential time are defined based on how quickly runtime grows with size. Big-O notation represents the asymptotic upper bound of a function's growth rate to classify algorithms.
Chapter 1 Class 12 Computer Science Unit 1ssusera7a08a
The document discusses the basics of Python programming language. It provides an introduction to Python, describing how it is an interpreted, high-level and general-purpose programming language. It then covers Python features, data types, operators, and how to work in both interactive and script modes in Python. The document also discusses topics like variables, data handling, arithmetic operators, comparison operators, and more with examples.
This document summarizes an integrated control system design tool that was developed to analyze and design intelligent control systems. The tool allows users to:
- Build interactive CAD models for control system design
- Incorporate various libraries and integrate popular AI techniques
- Simulate systems using mixed continuous/discrete event simulation
- Represent systems with generalized Petri net and fuzzy system models
- Program using a new matrix-based language
- Model dead time elements flexibly
- Apply the tool to examples like adaptive fuzzy PID control and liquid level control
The document outlines the goals, background, achievements, related tools, and plans for future work regarding the development of the integrated intelligent control system design tool.
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
Problem solving using computers involves transforming a problem description into a solution using problem-solving strategies, techniques, and tools. Programming is a problem-solving activity where instructions are written for a computer to solve something. The document then discusses the steps in problem solving like definition, analysis, approach, coding, testing etc. It provides examples of algorithms, flowcharts, pseudocode and discusses concepts like top-down design, time complexity, space complexity and ways to swap variables and count values.
The document provides an introduction and recap of data structures and algorithms concepts. It discusses different data structures like arrays, linked lists, stacks, queues, trees and graphs. It summarizes the time complexities of common operations on these data structures. It also introduces recursion as a programming technique, explaining the general structure of recursive functions and how function calls use the program stack.
This document provides an introduction to R for econometrics. It covers installing R and RStudio, the basics of R including expressions, variables, functions, modules and packages. It demonstrates some key features of R through examples and discusses why R is popular for data analysis and science. Flow control structures like if/else, while and for loops are also introduced. Additional appendices provide more details on objects, operators, sampling, common functions and basic graphics in R.
This document provides an introduction to R for econometric analysis. It discusses installing R and RStudio, why R is useful for data science and analysis tasks, basic R syntax like variables, functions, modules and packages. It also demonstrates some R code examples and covers flow control, objects, operators, sampling, common functions and basic graphics. The document is intended to give students a quick start in learning the R programming language.
The document summarizes computational aspects of vehicle routing problems. It discusses time complexity and space complexity, and how they are measured as functions of problem size. It provides examples of calculating complexity for different algorithms. It also discusses common data structures for representing routes, including array lists, doubly linked lists, and their pros and cons for different operations. The document outlines Java code examples for comparing route representation using these data structures.
In this presentation we introduce a family of gossiping algorithms whose members share the same structure though they vary their performance in function of a combinatorial parameter. We show that such parameter may be considered as a “knob” controlling the amount of communication parallelism characterizing the algorithms. After this we introduce procedures to operate the knob and choose parameters matching the amount of communication channels currently provided by the available communication system(s). In so doing we provide a robust mechanism to tune the production of requests for communication after the current operational conditions of the consumers of such requests. This can be used to achieve high performance and programmatic avoidance of undesirable events such as message collisions.
Paper available at https://dl.dropboxusercontent.com/u/67040428/Articles/pdp12.pdf
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
4. Copyright (c) 2011 Ioanna Dionysiou
Intermediate Code Representation
Parsing
Type-checking
Intermediate
Form
Generation
Syntax tree
Assumption: Source code is parsed and type-checked
5. Copyright (c) 2011 Ioanna Dionysiou
Intermediate Languages
So far, we have seen one kind of intermediate
representation
– Syntax trees (2nd week of classes)
• Natural hierarchical structure of program
A new kind
– 3-address code
• Abstract form
6. Copyright (c) 2011 Ioanna Dionysiou
3-address code
It is a sequence of statements of the general
form
Names
Constants
temporaries
Arithmetic operator
Logical operator
x := y op z
7. Copyright (c) 2011 Ioanna Dionysiou
3-address code
/* source language expression */
x + y * z
/* 3-address statements */
t1 := y * z
t2 := x + t1
Where t1, t2 are compiler-
generated temporary names
Variable names can appear
directly in 3-address
statements
8. Copyright (c) 2011 Ioanna Dionysiou
3-address code
/* source language expression */
a := b * -c + b * -c
/* 3-address statements */
t1 := -c
t2 := b * t1
t3 := -c
t4 := b * t3
t5 := t2 + t4
a := t5
In other words, for each
interior node in the syntax
tree we create a new
temporary variable
+
:=
a
*
b unimus
c
*
b unimus
c
9. Copyright (c) 2011 Ioanna Dionysiou
Types of 3-address statements
– Assignment statement
x := y op z
– Assignment instruction
x := op z
– Copy statement
x := y
– Unconditional jump
goto L
– Conditional jump
if x relop y goto L
Procedural call
p(x1,x2,…,xn)
param x1
param x2
param xn
call p, n
Indexed assignments
x := y[i] , x[i] := y
Address and pointer
assignments
x := &y, x := *y, *x := y
10. Copyright (c) 2011 Ioanna Dionysiou
Implementation of 3-address
3-address statement is an abstract form of
intermediate code
Need a concrete form
– Records with fields for operator and operands
• Quadruples
• Triples
• Indirect triples
11. Copyright (c) 2011 Ioanna Dionysiou
Quadruples
It is a record structure with 4 fields
• Operator
• Argument 1
• Argument 2
• Result
op arg1 arg2 result
unimus c t1
* b t1 t2
unimus c t3
* b t3 t4
+ t2 t4 t5
:= t5 a
a:= b * -c + b * -c
t1 := -c
t2 := b * t1
t3 := -c
t4 := b * t3
t5 := t2 + t4
a := t5
12. Copyright (c) 2011 Ioanna Dionysiou
op arg1 arg2
unimus c
* b (0)
unimus c
* b (2)
+ (1) (3)
assign a (4)
a:= b * -c + b * -c
t1 := -c
t2 := b * t1
t3 := -c
t4 := b * t3
t5 := t2 + t4
a := t5
Triples
It is a record structure with 3 fields
• Operator
• Argument 1 (pointer to symbol table or triple)
• Argument 2 (pointer to symbol table or triple)
– Idea
– avoid entering temporary names to symbol table
– Refer to a temp value by the position of that statement that
computes it
13. Copyright (c) 2011 Ioanna Dionysiou
op arg1 arg2
unimus c
* b (14)
unimus c
* b (16)
+ (15) (17)
assign a (18)
statement
(0) (14)
(1) (15)
(2) (16)
(3) (17)
(4) (18)
(5) (19)
Indirect Triples
It is a record structure with 3 fields
• Operator
• Argument 1 (pointer to symbol table or triple)
• Argument 2 (pointer to symbol table or triple)
– Idea
• List pointers to triples instead listing triples
14. In-class Exercise
Show the 3-address code for the following
statements:
a := 5 + 6
c := a + 3
Try to optimize the 3-address code generated
Copyright (c) 2011 Ioanna Dionysiou
16. Copyright (c) 2011 Ioanna Dionysiou
Source Language Issues
Before considering code generation
– Need to relate static program source to actions
that must take place at runtime to implement this
program
• Relationship between names and data objects
• Allocation and deallocation of data objects is managed
by runtime support package
– Routines loaded with the generated target code
• Depending on the language, the runtime environment
may be
– Fully static, stack-based or dynamic
– Type of environment determines the need to use stack, heap
or both
17. Copyright (c) 2011 Ioanna Dionysiou
Program and Procedures
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Procedure definition
procedure name
associated with
procedure body
Procedure call
Actual parameters
Formal parameters
18. Copyright (c) 2011 Ioanna Dionysiou
Program and Procedures
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Procedure Activation
An execution of a
procedure body
Lifetime of Procedure
Activation
Sequence of steps between
the first and last statements
in the execution of the
procedure body, including
time spent executing other
procedures called by p
Actual parameters
Formal parameters
19. Copyright (c) 2011 Ioanna Dionysiou
Flow of control
Assumptions about the flow of control among
procedures during program execution
– Control flows sequentially
– Execution of a procedure starts at the beginning
of procedure body and eventually returns control
to the point immediately following the place where
the procedure was called
• In this case we can use trees to illustrate the flow of
control in a program
• goto statement (transfers control to another point)
20. Copyright (c) 2011 Ioanna Dionysiou
Procedure Activation
Each time control enters a procedure q from
procedure p, it eventually returns to p (if no
errors occur)
– Activation of procedure p
– Activation of procedure q
– Return to activation of procedure p
Consider
– lifetime(p) and lifetime(q)
• Lifetime(p) and lifetime(q) are non-overlapping
• Lifetime(p) and lifetime(q) are nested
– See example above
21. Copyright (c) 2011 Ioanna Dionysiou
Recursive Procedures
A recursive procedure is a procedure that
calls itself
– A new activation begins before an earlier
activation of the same procedure has ended
– Several activations for procedure p exist at time t
A recursive procedure is a procedure p that
calls another procedure q, which in turns calls
procedure p
– Procedure p Procedure q
• Call to procedure q Call to procedure p
22. Copyright (c) 2011 Ioanna Dionysiou
Activation tree
We can use a tree (activation tree) to depict
the way control enters and leaves activations
How to build an activation tree
– Each node represents an activation of a
procedure
• The root represents the activation of the main program
• The node for a is the parent of node b iff control flows
from activation a to b
• The node for a is to the left of the node for b iff the
lifetime(a) occurs before lifetime(b)
23. Copyright (c) 2011 Ioanna Dionysiou
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Can you build the activation tree
for this program?
Use
s - activation of main program sort
r - activation of readarray
p - activation of partition
q(x,y) - activation of quicksort
Start with
s as the root of the tree
r and q(1,9) are its children, etc…
Activation Tree for a program
24. Copyright (c) 2011 Ioanna Dionysiou
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
q(1,9)
s
r
p(1,9) q(1,3) q(5,9)
p(1,3) q(1,0) q(2,3) p(5,9) q(5,5) q(7,9)
p(2,3) q(2,1) q(3,3) p(7,9) q(7,7) q(9,9)
Activation Tree for a program
25. Copyright (c) 2011 Ioanna Dionysiou
Control Stack and Activation Tree
Flow of control in a program
– Depth-first traversal of the activation tree
– Use a stack called control stack to keep track of
the live procedure activations
• Push node for an activation onto the stack as the
activation begins
• Pop node for an activation off the stack when the
activation ends
• Control Stack contents
– Node n is at top of the control stack
– Stack contains the nodes along the path from n to the root
26. Copyright (c) 2011 Ioanna Dionysiou
q(1,9)
s
r
p(1,9) q(1,3)
p(1,3) q(1,0) q(2,3)
r, p(1,9), p(1,3) and q(1,0)
have executed to completion
(dashed lines)
Stack contains
q(2,3)
q(1,3)
q(1,9)
s
top
Activation Tree for a program
27. Copyright (c) 2011 Ioanna Dionysiou
Scope of declaration
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Scope of variables depends
on the language scope rules
(1) Local
(2) Nonlocal
Same name, different scope
28. Copyright (c) 2011 Ioanna Dionysiou
Bindings of names
Environment
– Function that maps a name to a storage location
• f: name storage location
State
– Function that maps a storage location to a value
• g: storage location value
g( f(name) ) = value
29. Copyright (c) 2011 Ioanna Dionysiou
Bindings of names
Consider storage location 100 is associated with
variable x and it currently holds value 0
– Environment
• x is bound to storage location 100
– State
• Value held is 0
Consider assignment statement x:=10
– Environment
• x is still bound to storage location 100
– State
• Value held is 10
30. Copyright (c) 2011 Ioanna Dionysiou
Bindings of names
A binding is the dynamic counterpart of a declaration
– Pascal local variable name in a procedure is bound to a different
storage location in each activation of a procedure
STATIC NOTION DYNAMIC COUNTERPART
Definition of procedure Activations of the procedure
Declaration of name Bindings of the name
Scope of declaration Lifetime of binding
31. Copyright (c) 2011 Ioanna Dionysiou
Lecture Outline
Source language issues
– Activation trees, control stacks, scope of
declaration, bindings
Storage Organization
– Activation records
Storage Allocation Strategies
– Static allocation, stack allocation, heap allocation
32. Copyright (c) 2011 Ioanna Dionysiou
Storage Organization
Suppose that the compiler obtains memory
from the OS so that it can execute the
compiled program
– Program gets loaded on a newly created process
This runtime storage must hold
– Generated target code
– Data objects
– A counterpart of the control stack to keep track of
procedure activations
33. Copyright (c) 2011 Ioanna Dionysiou
code for function 1
code for function 2
code for function n
. . .
global / static area
stack
heap
free space
Runtime Memory
PASCAL and C use extensions of the control
stack to manage activations of procedures
Stack contains information about register values,
value of program counter and data objects whose
lifetimes are contained in that of an activation
Heap holds all other information. For example,
activations that cannot be represented as a tree.
By convention, stack grows down and the top of
the stack is drawn towards the bottom of this slide
(value of top is usually kept in a register)
34. Copyright (c) 2011 Ioanna Dionysiou
code for function 1
code for function 2
code for function n
. . .
global / static area
stack
heap
free space
Runtime Memory
code for function 1
code for function 2
code for function n
. . .
global / static area
stack
heap
free space
Stack grows
35. Copyright (c) 2011 Ioanna Dionysiou
Activation Record
Information needed by a single
execution of a procedure is
managed using an activation
record or frame
– Not all compilers use all of the
fields
– Pascal and C push activation
record on the runtime stack
when procedure is called and
pop the activation record off the
stack when control returns to
the caller
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
36. Copyright (c) 2011 Ioanna Dionysiou
Activation Record
1) Temporary values
e.g. those arising in the evaluation of
expressions
2) Local data
Data that is local to an execution of the
procedure
3) Saved machine status
State of the machine info before procedure
is called. Values of program counter and
machine registers that have to be restored
when control returns from the procedure
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
37. Copyright (c) 2011 Ioanna Dionysiou
Activation Record
4) Access Link
refer to non-local data held in other activation records
5) Control link
points to the activation record of the caller
6) Actual parameters
used by the calling procedure to supply parameters to the
called procedure
(in practice these are passed in registers)
7) Returned value
used by the called procedure to return a value to the
calling procedure
(in practice it is returned in a register)
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
38. Copyright (c) 2011 Ioanna Dionysiou
Local data
The field for local data is set when
declarations in a procedure are examined
during compile time
– Variable-length data is not stored here
– Keep a count of the memory locations that have
been allocated so far
– Determine a relative address (offset) of the
storage for a local with respect to some position
(e.g. beginning of the frame)
• Multibyte objects are stored in consecutive bytes and
given the address of the first byte
39. Copyright (c) 2011 Ioanna Dionysiou
Lecture Outline
Source language issues
– Activation trees, control stacks, scope of
declaration, bindings
Storage Organization
– Activation records
Storage Allocation Strategies
– Static allocation, stack allocation, heap allocation
40. Copyright (c) 2011 Ioanna Dionysiou
Storage-allocation strategies
There are three storage allocation strategies:
– Static allocation
– Stack-based allocation
– Dynamic (or heap-based) allocation
41. Copyright (c) 2011 Ioanna Dionysiou
Static Allocation
In a static environment (Fortran 77) there are
a number of restrictions:
– Size of data objects are known at compile time
– No recursive procedures
– No dynamic memory allocation
Only one copy of each procedure activation
record exists at time t
– We can allocate storage at compile time
• Bindings do not change at runtime
• Every time a procedure is called, the same bindings
occur
42. Copyright (c) 2011 Ioanna Dionysiou
Static Allocation
int i = 10;
int f(int j)
{
int k;
int m;
…
}
main()
{
int k;
f(k);
}
code for function 1
code for function 2
code for function n
. . .
global / static area
stack
heap
free space
code main()
code f()
i (int)
k (int)
k (int)
m (int)
main()
Activation
record
f()
Activation
record
43. Copyright (c) 2011 Ioanna Dionysiou
Stack-based Allocation
In a stack-based allocation, the previous
restrictions are lifted (Pascal, C, etc)
– procedures are allowed to be called recursively
• Need to hold multiple activation records for the same
procedure
• Created as required and placed on the stack
– Each record will maintain a pointer to the record that activated
it
– On completion, the current record will be deleted from the
stack and control is passed to the calling record
– Dynamic memory allocation is allowed
– Pointers to data locations are allowed
44. Copyright (c) 2011 Ioanna Dionysiou
Stack-based Allocation
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Position in
Activation Tree
Activation Records
On Stack
s
s
a (array)
45. Copyright (c) 2011 Ioanna Dionysiou
Stack-based Allocation
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Position in
Activation Tree
Activation Records
On Stack
s
a (array)
s
r r
i (integer)
46. Copyright (c) 2011 Ioanna Dionysiou
Stack-based Allocation
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Position in
Activation Tree
Activation Records
On Stack
s
a (array)
s
r q(1,9)
i (integer)
q(1,9)
47. Copyright (c) 2011 Ioanna Dionysiou
Stack-based Allocation
PROGRAM sort(input,output);
VAR a : array[0..10] of Integer;
PROCEDURE readarray;
VAR i : Integer;
BEGIN
for i:= 1 to 9 do read(a[i]);
END;
FUNCTION partition(y,z : Integer): Integer;
VAR i,j,x,v : Integer;
BEGIN
…
END;
PROCEDURE quicksort(m,n : Integer);
VAR i : Integer;
BEGIN
if (n > m) then BEGIN
i := partition(m,n);
quicksort(m, i-1);
quicksort(i+1,n)
END
END;
BEGIN /* of main */
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
END.
Position in
Activation Tree
Activation Records
On Stack
s
a (array)
s
r q(1,9)
i (integer)
q(1,9)
q(1,3)
p(1,9)
q(1,3)
i (integer)
48. Copyright (c) 2011 Ioanna Dionysiou
Calling Sequences
Procedure calls are
implemented by generating
calling sequences in the
target code
– Call sequence: allocates
activation record and enters
information into fields
– Return sequence: restores the
state of the machine so that
the calling procedure can
continue execution
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
49. Copyright (c) 2011 Ioanna Dionysiou
Calling Sequences
Why placing returned value and
actual parameters next to the
activation record of the caller?
– Caller can access these values
using offsets from its own activation
record
– No need to know the middle part of
the callee’s activation record
caller
callee
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
50. Copyright (c) 2011 Ioanna Dionysiou
Calling Sequences
How do we calculate offset?
– Maintain a register that points to
the end of the machine status
field in an activation record
– Top_sp is known to the caller, so
it can be responsible for setting it
before control flows to the called
procedure
– Callee can access its temporaites
and local data using offsets from
top_sp
caller
callee
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
returned value
actual parameters
optional control link
optional access link
saved machine status
local data
temporaries
top_sp
51. Copyright (c) 2011 Ioanna Dionysiou
Call Sequence
The caller evaluates actuals
The caller
– stores a return address and the old value of
top_sp into the callee’s activation record
– increments top_sp; that is moved past the caller’s
local data and temporaries and the callee’s
parameter and status fields
The callee
– saves register values and other status information
The callee
– initializes its local data and begins execution
52. Copyright (c) 2011 Ioanna Dionysiou
Return Sequence
The callee places a return value next to the
activation record of the caller
Using the information in the status field, the
callee
– restores top_sp and other registers
– braches to a return address in the caller’s code
Although top_sp has been decremented, the
caller can copy the returned value into its own
activation record and use it to evaluate an
expression
53. Copyright (c) 2011 Ioanna Dionysiou
Dangling References
Whenever storage is deallocated, the problem
of dangling references arises
– Occurs when there is a reference to storage that
has been deallocated
– Logical error
• Mysterious bugs can appear
54. Copyright (c) 2011 Ioanna Dionysiou
Dangling References
int *dangle()
{
int i = 23;
return &i;
}
main()
{
int *p;
p = dangle();
}
What’s the problem?
55. Copyright (c) 2011 Ioanna Dionysiou
Dangling References
int *dangle()
{
int i = 23;
return &i;
}
main()
{
int *p;
p = dangle();
}
Local variable i only exists in
dangle()
When procedure completes
execution and control is
transferred to main(), the space for
i does not exist anymore (pop
activation record for dangle off the
stack)
Pointer p is a dangling reference
56. Copyright (c) 2011 Ioanna Dionysiou
Dynamic Allocation
Returning the address of a local variable is defined to be a
logical error (e.g. in C)
In a dynamic environment there is no such restriction
– All variables and activation records must be maintained for as long as
there are references to them
• Callee outlives the caller
– It is also possible to return pointers to local functions
– Must deallocate space when procedures and variables are no longer
needed (garbage collection)
57. Copyright (c) 2011 Ioanna Dionysiou
Dynamic Allocation
Use a heap to maintain these records
– Also called free store
– Heap management is challenging