Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lecture 20 Types / Offsets Revisited Topics Procedural Abstraction Activation records Readings: 8.2 March 29, 2006 CSCE 531 Compiler Construction."— Presentation transcript:

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

2 – 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 – 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 – 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 – 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 – 6 – CSCE 531 Spring 2006 Final reductions of statement lists

7 – 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 – 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 – 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 – 10 – CSCE 531 Spring 2006

11 – 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 – 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 – 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 – 14 – CSCE 531 Spring 2006 Type Example

15 – 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 – 16 – CSCE 531 Spring 2006 Handling Records

17 – 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).


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

Similar presentations


Ads by Google