Lecture 20 Types / Offsets Revisited Topics Procedural Abstraction Activation records Readings: 8.2 March 29, 2006 CSCE 531 Compiler Construction.

Slides:



Advertisements
Similar presentations
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
Advertisements

CPSC 388 – Compiler Design and Construction
Chapter 6 Intermediate Code Generation
Intermediate Code Generation
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
1 Compiler Construction Intermediate Code Generation.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Generation I Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Lecture 16 Subroutine Calls and Parameter Passing Semantics Dragon: Sec. 7.5 Fischer: Sec Procedure declaration procedure p( a, b : integer, f :
Lecture 19 Nested Scopes Topics Procedural Abstraction Activation records Readings: 7.4 March 20, 2006 CSCE 531 Compiler Construction.
Lecture # 20 Type Systems. 2 A type system defines a set of types and rules to assign types to programming language constructs Informal type system rules,
Compiler Construction
Lesson 12 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Compiler Construction Sohail Aslam Lecture Boolean Expressions E → E 1 and M E 2 {backpatch(E 1.truelist, M.quad); E.truelist = E 2.truelist; E.falselist.
Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error.
ISBN Chapter 10 Implementing Subprograms.
Lecture 15 Control Flow Topics Review Positional Encoding of Booleans Short Circuit Evaluation Control Flow Statements Readings: 8.4, 8.6 March 13, 2006.
Lecture 18 Procedures Topics Procedural Abstraction Activation records Readings: 7.4 March 20, 2006 CSCE 531 Compiler Construction.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Lecture 22 Code Generation Topics Arrays Code Generation Readings: 9 April 10, 2006 CSCE 531 Compiler Construction.
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Static checking and symbol table Chapter 6, Chapter 7.6 and Chapter 8.2 Static checking: check whether the program follows both the syntactic and semantic.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
CS 2104 Prog. Lang. Concepts Subprograms
Compiler Construction
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
Lesson 11 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
Computer Engineering Rabie A. Ramadan Lecture 5.
A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University NESTED SUBPROGRAMS.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
Review: Syntax directed translation. –Translation is done according to the parse tree. Each production (when used in the parsing) is a sub- structure of.
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Chapter 8: Semantic Analyzer1 Compiler Designs and Constructions Chapter 8: Semantic Analyzer Objectives: Syntax-Directed Translation Type Checking Dr.
User-Defined Functions (cont’d) - Reference Parameters.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
CSCE 531 Compiler Construction
Lecture 9 Symbol Table and Attributed Grammars
Semantic Analysis Type Checking
Context-Sensitive Analysis
Constructing Precedence Table
CS 326 Programming Languages, Concepts and Implementation
Review: Chapter 5: Syntax directed translation
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Subject Name:COMPILER DESIGN Subject Code:10CS63
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Chapter 6 Intermediate-Code Generation
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Semantic Analysis Chapter 6.
SYNTAX DIRECTED DEFINITION
CS 432: Compiler Construction Lecture 11
Compiler Construction
Intermediate Code Generation Part I
C Language B. DHIVYA 17PCA140 II MCA.
Lecture 16 Boolean Expressions and Control Flow
Compiler Construction
Presentation transcript:

Lecture 20 Types / Offsets Revisited Topics Procedural Abstraction Activation records Readings: 8.2 March 29, 2006 CSCE 531 Compiler Construction

– 2 – CSCE 531 Spring 2006 Overview Last Time Review Semantics actions for function invocation Review Semantics actions for arglist Attribute placeList – list of identifiers Handling Function Definitions Today’s Lecture Final reductions of statement lists in programs/functions/procedures Passing Parameters Array.c Nested Scope Nested.c References: Section 8.2 Homework:

– 3 – CSCE 531 Spring 2006 Test 2 - TIME CHANGE !!!!! Wednesday April 5 7:00PM Wednesday April 5 7:00PM First Robotics Volunteers – Friday March 31, 5:00-7:00PM Graduate Assistants - I need to see after class! Graduate Assistants - I need to see after class! AARONS, AL-ABRI, BYRNES, GARRETT, GREGORY, KODUR, SAXENA, TEMLYAKOV, VARGHESE, TALATAM

– 4 – CSCE 531 Spring 2006 Some Questions  How do we handle running out of pace in quad arrays? Again with corrections  When an “if-then” statement is last statement in program (or function) how do we backpatch?

– 5 – CSCE 531 Spring 2006 Question on size of code arrays What happens when you run out of space? Nextquad > arraySize void gen(int op) { static int *opcode=NULL; static int *opcode=NULL; static int arraySize = 0; static int arraySize = 0; static int nextquad = 0; static int nextquad = 0; if (nextquad >= arraySize){ if (nextquad >= arraySize){ arraySize += ARRAY_INCREMENT; arraySize += ARRAY_INCREMENT; opcode = (int *) realloc(opcode, arraySize); opcode = (int *) realloc(opcode, arraySize); } opcode[nextquad++] = op; opcode[nextquad++] = op;} Need to be a globals Why?

– 6 – CSCE 531 Spring 2006 Final reductions of statement lists

– 7 – CSCE 531 Spring 2006 Precedence of Operators Dear Dr. Matthews: About the operator precedence, if I have a || b && c, a || b && c, What will be the order? Is that first evaluate b&&c then a || (b&&c) or first a || b then (a||b) && c? Best

– 8 – CSCE 531 Spring 2006 C type booleans – Not for Project 4!!! The grammar for handling the logical operator “not” Is B  NOT B Not B  '!' E, which would be fine in C { /*CODE FOR THE ('not' B) EXPRESSION*/ /*CODE FOR THE ('not' B) EXPRESSION*/ }

– 9 – CSCE 531 Spring 2006 Parameter Passing Call by value Call by value Call by reference Call by reference Copy-restore Copy-restore Call by name Call by name Logically the procedure is treated as a macro with the arguments substituted for the formal parameters Actually code passed for evaluating the argument is passed to the functions

– 10 – CSCE 531 Spring 2006

– 11 – CSCE 531 Spring 2006 Declarations within Functions/Procedures Figure 8.11 – differences in approaches P  { offset = 0;} D // place code instead of marker D  D ‘;’ D D  ID ‘:’ T{ enter(id.place, T.type, offset); offset = offset + T.width; offset = offset + T.width;}

– 12 – CSCE 531 Spring 2006 Types within the Declarations T  integer{ T.type = INTEGER; T.width = 4; } | double{ T.type = double; T.width = 8; } | double{ T.type = double; T.width = 8; } | array ‘[’ num ‘]’ of T1 { | array ‘[’ num ‘]’ of T1 { T.type = array(num.val, T1.type); T.type = array(num.val, T1.type); T.width = num.val * T1.width; T.width = num.val * T1.width; } | * T1{ T.type = pointer(T1.type); | * T1{ T.type = pointer(T1.type); T.width = 4; T.width = 4;}

– 13 – CSCE 531 Spring 2006 Representing Type Information Type tree Nodes Nodes Leaves = Base types: int, float Leaves = Base types: int, float Interior Nodes = Type Constructors Interior Nodes = Type Constructors Array (size, dimensions, type) or maybe array of array for 2 dimensions Pointer ( targetType) FuncReturning Record ( componentTypeList )

– 14 – CSCE 531 Spring 2006 Type Example

– 15 – CSCE 531 Spring 2006 Type Encoding Base types boolean 0000 char 0001 char 0001 int0010 double0011 Type constructor encodings - pointer01 array10 freturns11 Why encode at all?

– 16 – CSCE 531 Spring 2006 Handling Records

– 17 – CSCE 531 Spring 2006 Structural and Name Equivalence of Types Two identifiers are name equivalent if the types have the same name. Two identifiers are structurally equivalent if the types have the same structure (type tree).